eslint-plugin-jest 29.13.0 → 29.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -36,7 +36,7 @@ it('bar', () => {
|
|
|
36
36
|
expect(fixtures.length).toBeGreaterThan(-1);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
it('
|
|
39
|
+
it('qux', async () => {
|
|
40
40
|
const promiseValue = () => {
|
|
41
41
|
return something instanceof Promise
|
|
42
42
|
? something
|
|
@@ -77,7 +77,47 @@ const promiseValue = something => {
|
|
|
77
77
|
return something instanceof Promise ? something : Promise.resolve(something);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
it('
|
|
80
|
+
it('qux', async () => {
|
|
81
81
|
await expect(promiseValue()).resolves.toBe(1);
|
|
82
82
|
});
|
|
83
83
|
```
|
|
84
|
+
|
|
85
|
+
## Options
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"jest/no-conditional-in-test": [
|
|
90
|
+
"error",
|
|
91
|
+
{
|
|
92
|
+
"allowOptionalChaining": true
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `allowOptionalChaining`
|
|
99
|
+
|
|
100
|
+
Default: `true`
|
|
101
|
+
|
|
102
|
+
When set to `false`, optional chaining (`?.`) inside test bodies will be
|
|
103
|
+
reported as a conditional.
|
|
104
|
+
|
|
105
|
+
Examples of **incorrect** code when `allowOptionalChaining` is `false`:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
it('foo', () => {
|
|
109
|
+
const value = obj?.bar;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('bar', () => {
|
|
113
|
+
obj?.foo();
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Examples of **correct** code when `allowOptionalChaining` is `false`:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
it('foo', () => {
|
|
121
|
+
const value = obj!.bar;
|
|
122
|
+
});
|
|
123
|
+
```
|
|
@@ -15,10 +15,22 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
15
15
|
conditionalInTest: 'Avoid having conditionals in tests'
|
|
16
16
|
},
|
|
17
17
|
type: 'problem',
|
|
18
|
-
schema: [
|
|
18
|
+
schema: [{
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
allowOptionalChaining: {
|
|
22
|
+
type: 'boolean'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: false
|
|
26
|
+
}]
|
|
19
27
|
},
|
|
20
|
-
defaultOptions: [
|
|
21
|
-
|
|
28
|
+
defaultOptions: [{
|
|
29
|
+
allowOptionalChaining: true
|
|
30
|
+
}],
|
|
31
|
+
create(context, [{
|
|
32
|
+
allowOptionalChaining
|
|
33
|
+
}]) {
|
|
22
34
|
let inTestCase = false;
|
|
23
35
|
const maybeReportConditional = node => {
|
|
24
36
|
if (inTestCase) {
|
|
@@ -42,7 +54,10 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
42
54
|
IfStatement: maybeReportConditional,
|
|
43
55
|
SwitchStatement: maybeReportConditional,
|
|
44
56
|
ConditionalExpression: maybeReportConditional,
|
|
45
|
-
LogicalExpression: maybeReportConditional
|
|
57
|
+
LogicalExpression: maybeReportConditional,
|
|
58
|
+
...(!allowOptionalChaining && {
|
|
59
|
+
ChainExpression: maybeReportConditional
|
|
60
|
+
})
|
|
46
61
|
};
|
|
47
62
|
}
|
|
48
63
|
});
|