eslint-plugin-jest 24.0.2 → 24.1.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [24.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.2...v24.1.0) (2020-10-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **prefer-expect-assertions:** add `onlyFunctionsWithAsyncKeyword` option ([#677](https://github.com/jest-community/eslint-plugin-jest/issues/677)) ([d0cea37](https://github.com/jest-community/eslint-plugin-jest/commit/d0cea37ae0a8ab07b8082cedbaaf161bcc94c405))
|
|
7
|
+
|
|
1
8
|
## [24.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.1...v24.0.2) (2020-09-20)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -55,3 +55,45 @@ test('my test', () => {
|
|
|
55
55
|
expect(someThing()).toEqual('foo');
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
|
+
|
|
59
|
+
## Options
|
|
60
|
+
|
|
61
|
+
#### `onlyFunctionsWithAsyncKeyword`
|
|
62
|
+
|
|
63
|
+
When `true`, this rule will only warn for tests that use the `async` keyword.
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"rules": {
|
|
68
|
+
"jest/prefer-expect-assertions": [
|
|
69
|
+
"warn",
|
|
70
|
+
{ "onlyFunctionsWithAsyncKeyword": true }
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
When `onlyFunctionsWithAsyncKeyword` option is set to `true`, the following
|
|
77
|
+
pattern would be a warning:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
test('my test', async () => {
|
|
81
|
+
const result = await someAsyncFunc();
|
|
82
|
+
expect(result).toBe('foo');
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
While the following patterns would not be considered warnings:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
test('my test', () => {
|
|
90
|
+
const result = someFunction();
|
|
91
|
+
expect(result).toBe('foo');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('my test', async () => {
|
|
95
|
+
expect.assertions(1);
|
|
96
|
+
const result = await someAsyncFunc();
|
|
97
|
+
expect(result).toBe('foo');
|
|
98
|
+
});
|
|
99
|
+
```
|
|
@@ -39,13 +39,27 @@ var _default = (0, _utils.createRule)({
|
|
|
39
39
|
suggestRemovingExtraArguments: 'Remove extra arguments'
|
|
40
40
|
},
|
|
41
41
|
type: 'suggestion',
|
|
42
|
-
schema: [
|
|
42
|
+
schema: [{
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
onlyFunctionsWithAsyncKeyword: {
|
|
46
|
+
type: 'boolean'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false
|
|
50
|
+
}]
|
|
43
51
|
},
|
|
44
|
-
defaultOptions: [
|
|
52
|
+
defaultOptions: [{
|
|
53
|
+
onlyFunctionsWithAsyncKeyword: false
|
|
54
|
+
}],
|
|
45
55
|
|
|
46
|
-
create(context) {
|
|
56
|
+
create(context, [options]) {
|
|
47
57
|
return {
|
|
48
58
|
'CallExpression[callee.name=/^(it|test)$/][arguments.1.body.body]'(node) {
|
|
59
|
+
if (options.onlyFunctionsWithAsyncKeyword && !node.arguments[1].async) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
const testFuncBody = node.arguments[1].body.body;
|
|
50
64
|
|
|
51
65
|
if (!isFirstLineExprStmt(testFuncBody)) {
|