eslint-plugin-jest 28.3.0 → 28.4.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/README.md
CHANGED
|
@@ -363,7 +363,7 @@ set to warn in.\
|
|
|
363
363
|
| [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | | | |
|
|
364
364
|
| [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | | | |
|
|
365
365
|
| [valid-describe-callback](docs/rules/valid-describe-callback.md) | Enforce valid `describe()` callback | ✅ | | | |
|
|
366
|
-
| [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ✅ | |
|
|
366
|
+
| [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ✅ | | 🔧 | |
|
|
367
367
|
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Require promises that have expectations in their chain to be valid | ✅ | | | |
|
|
368
368
|
| [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ✅ | | 🔧 | |
|
|
369
369
|
|
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
💼 This rule is enabled in the ✅ `recommended`
|
|
4
4
|
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
5
|
|
|
6
|
+
🔧 This rule is automatically fixable by the
|
|
7
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
8
|
+
|
|
6
9
|
<!-- end auto-generated rule header -->
|
|
7
10
|
|
|
11
|
+
> [!NOTE] Test function will be fixed if it is async and does not have await in
|
|
12
|
+
> the async assertion.
|
|
13
|
+
|
|
8
14
|
Ensure `expect()` is called with a single argument and there is an actual
|
|
9
15
|
expectation made.
|
|
10
16
|
|
|
@@ -49,7 +49,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
49
49
|
return {
|
|
50
50
|
ImportDeclaration(node) {
|
|
51
51
|
node.specifiers.forEach(specifier => {
|
|
52
|
-
if (specifier.type ===
|
|
52
|
+
if (specifier.type === _utils.AST_NODE_TYPES.ImportSpecifier) {
|
|
53
53
|
importedFunctionsWithSource[specifier.local.name] = node.source.value;
|
|
54
54
|
}
|
|
55
55
|
});
|
|
@@ -28,6 +28,14 @@ const getPromiseCallExpressionNode = node => {
|
|
|
28
28
|
return null;
|
|
29
29
|
};
|
|
30
30
|
const findPromiseCallExpressionNode = node => node.parent?.parent && [_utils.AST_NODE_TYPES.CallExpression, _utils.AST_NODE_TYPES.ArrayExpression].includes(node.parent.type) ? getPromiseCallExpressionNode(node.parent) : null;
|
|
31
|
+
const findFirstAsyncFunction = ({
|
|
32
|
+
parent
|
|
33
|
+
}) => {
|
|
34
|
+
if (!parent) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return (0, _utils2.isFunction)(parent) && parent.async ? parent : findFirstAsyncFunction(parent);
|
|
38
|
+
};
|
|
31
39
|
const getParentIfThenified = node => {
|
|
32
40
|
const grandParentNode = node.parent?.parent;
|
|
33
41
|
if (grandParentNode && grandParentNode.type === _utils.AST_NODE_TYPES.CallExpression && grandParentNode.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(grandParentNode.callee.property) && ['then', 'catch'].includes((0, _utils2.getAccessorValue)(grandParentNode.callee.property)) && grandParentNode.parent) {
|
|
@@ -65,6 +73,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
65
73
|
asyncMustBeAwaited: 'Async assertions must be awaited{{ orReturned }}',
|
|
66
74
|
promisesWithAsyncAssertionsMustBeAwaited: 'Promises which return async assertions must be awaited{{ orReturned }}'
|
|
67
75
|
},
|
|
76
|
+
fixable: 'code',
|
|
68
77
|
type: 'suggestion',
|
|
69
78
|
schema: [{
|
|
70
79
|
type: 'object',
|
|
@@ -242,7 +251,19 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
242
251
|
orReturned
|
|
243
252
|
},
|
|
244
253
|
messageId: finalNode === targetNode ? 'asyncMustBeAwaited' : 'promisesWithAsyncAssertionsMustBeAwaited',
|
|
245
|
-
node
|
|
254
|
+
node,
|
|
255
|
+
fix(fixer) {
|
|
256
|
+
if (!findFirstAsyncFunction(finalNode)) {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
const returnStatement = finalNode.parent?.type === _utils.AST_NODE_TYPES.ReturnStatement ? finalNode.parent : null;
|
|
260
|
+
if (alwaysAwait && returnStatement) {
|
|
261
|
+
const sourceCodeText = (0, _utils2.getSourceCode)(context).getText(returnStatement);
|
|
262
|
+
const replacedText = sourceCodeText.replace('return', 'await');
|
|
263
|
+
return fixer.replaceText(returnStatement, replacedText);
|
|
264
|
+
}
|
|
265
|
+
return fixer.insertTextBefore(finalNode, 'await ');
|
|
266
|
+
}
|
|
246
267
|
});
|
|
247
268
|
if (isParentArrayExpression) {
|
|
248
269
|
pushPromiseArrayException(finalNode.loc);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.4.0",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"optional": true
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
|
-
"packageManager": "yarn@3.8.
|
|
127
|
+
"packageManager": "yarn@3.8.2",
|
|
128
128
|
"engines": {
|
|
129
129
|
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
|
|
130
130
|
},
|