eslint-plugin-jest 26.1.2 → 26.1.5
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 +30 -2
- package/docs/rules/no-conditional-expect.md +1 -1
- package/docs/rules/no-deprecated-functions.md +1 -2
- package/docs/rules/no-identical-title.md +1 -1
- package/docs/rules/no-jasmine-globals.md +2 -2
- package/docs/rules/no-jest-import.md +1 -1
- package/docs/rules/no-large-snapshots.md +2 -2
- package/docs/rules/no-standalone-expect.md +1 -1
- package/docs/rules/prefer-comparison-matcher.md +1 -1
- package/docs/rules/prefer-equality-matcher.md +1 -1
- package/docs/rules/prefer-expect-assertions.md +1 -1
- package/docs/rules/prefer-hooks-on-top.md +1 -1
- package/docs/rules/prefer-lowercase-title.md +2 -2
- package/docs/rules/valid-expect.md +2 -2
- package/lib/rules/prefer-expect-assertions.js +2 -0
- package/lib/rules/prefer-snapshot-hint.js +15 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -59,6 +59,34 @@ doing:
|
|
|
59
59
|
This is included in all configs shared by this plugin, so can be omitted if
|
|
60
60
|
extending them.
|
|
61
61
|
|
|
62
|
+
### Running rules only on test-related files
|
|
63
|
+
|
|
64
|
+
The rules provided by this plugin assume that the files they are checking are
|
|
65
|
+
test-related. This means it's generally not suitable to include them in your
|
|
66
|
+
top-level configuration as that applies to all files being linted which can
|
|
67
|
+
include source files.
|
|
68
|
+
|
|
69
|
+
You can use
|
|
70
|
+
[overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
|
|
71
|
+
to have ESLint apply additional rules to specific files:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"extends": ["eslint:recommended"],
|
|
76
|
+
"overrides": [
|
|
77
|
+
{
|
|
78
|
+
"files": ["test/**"],
|
|
79
|
+
"plugins": ["jest"],
|
|
80
|
+
"extends": ["plugin:jest/recommended"],
|
|
81
|
+
"rules": { "jest/prefer-expect-assertions": "off" }
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"rules": {
|
|
85
|
+
"indent": ["error", 2]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
62
90
|
### Jest `version` setting
|
|
63
91
|
|
|
64
92
|
The behaviour of some rules (specifically [`no-deprecated-functions`][]) change
|
|
@@ -211,8 +239,8 @@ adjust your eslint config as outlined
|
|
|
211
239
|
|
|
212
240
|
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
213
241
|
the rules here will fallback to doing nothing if type information is not
|
|
214
|
-
available, meaning
|
|
215
|
-
on JavaScript and TypeScript projects.
|
|
242
|
+
available, meaning it's safe to include them in shared configs that could be
|
|
243
|
+
used on JavaScript and TypeScript projects.
|
|
216
244
|
|
|
217
245
|
Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
|
|
218
246
|
as it extends the original `unbound-method` rule from that plugin.
|
|
@@ -107,7 +107,7 @@ While you can use `expect.assertions` & `expect.hasAssertions` for these
|
|
|
107
107
|
situations, they only work with `expect`.
|
|
108
108
|
|
|
109
109
|
A better way to handle this situation is to introduce a wrapper to handle the
|
|
110
|
-
catching, and otherwise
|
|
110
|
+
catching, and otherwise return a specific "no error thrown" error if nothing is
|
|
111
111
|
thrown by the wrapped function:
|
|
112
112
|
|
|
113
113
|
```typescript
|
|
@@ -37,8 +37,7 @@ Originally, the `requireActual` & `requireMock` the `requireActual`&
|
|
|
37
37
|
|
|
38
38
|
These functions were later moved onto the `jest` object in order to be easier
|
|
39
39
|
for type checkers to handle, and their use via `require` deprecated. Finally,
|
|
40
|
-
the release of Jest 26 saw them removed from the `require` function
|
|
41
|
-
together.
|
|
40
|
+
the release of Jest 26 saw them removed from the `require` function altogether.
|
|
42
41
|
|
|
43
42
|
### `jest.runTimersToTime`
|
|
44
43
|
|
|
@@ -7,7 +7,7 @@ fix.
|
|
|
7
7
|
|
|
8
8
|
## Rule Details
|
|
9
9
|
|
|
10
|
-
This rule looks at the title of every test and test
|
|
10
|
+
This rule looks at the title of every test and test suite. It will report when
|
|
11
11
|
two test suites or two test cases at the same level of a test suite have the
|
|
12
12
|
same title.
|
|
13
13
|
|
|
@@ -9,8 +9,8 @@ API.
|
|
|
9
9
|
|
|
10
10
|
### Rule details
|
|
11
11
|
|
|
12
|
-
This rule reports on any usage of Jasmine globals which is not ported to Jest,
|
|
13
|
-
and suggests
|
|
12
|
+
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
|
|
13
|
+
and suggests alternatives from Jest's own API.
|
|
14
14
|
|
|
15
15
|
### Default configuration
|
|
16
16
|
|
|
@@ -118,8 +118,8 @@ External). Use `inlineMaxSize` for
|
|
|
118
118
|
[Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
|
|
119
119
|
size and `maxSize` for
|
|
120
120
|
[External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
|
|
121
|
-
If only `maxSize` is provided on options, the value of `maxSize` will be used
|
|
122
|
-
both snapshot types (Inline and External).
|
|
121
|
+
If only `maxSize` is provided on options, the value of `maxSize` will be used
|
|
122
|
+
for both snapshot types (Inline and External).
|
|
123
123
|
|
|
124
124
|
Since `eslint-disable` comments are not preserved by Jest when updating
|
|
125
125
|
snapshots, you can use the `allowedSnapshots` option to have specific snapshots
|
|
@@ -61,7 +61,7 @@ describe('a test', () => {
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
\*Note that this rule will not trigger if the helper function is never used even
|
|
64
|
-
|
|
64
|
+
though the `expect` will not execute. Rely on a rule like no-unused-vars for
|
|
65
65
|
this case.
|
|
66
66
|
|
|
67
67
|
### Options
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
|
|
2
2
|
|
|
3
|
-
Jest has a number of built-in matchers for comparing numbers which allow for
|
|
3
|
+
Jest has a number of built-in matchers for comparing numbers, which allow for
|
|
4
4
|
more readable tests and error messages if an expectation fails.
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)
|
|
2
2
|
|
|
3
|
-
Jest has built-in matchers for expecting equality which allow for more readable
|
|
3
|
+
Jest has built-in matchers for expecting equality, which allow for more readable
|
|
4
4
|
tests and error messages if an expectation fails.
|
|
5
5
|
|
|
6
6
|
## Rule details
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Suggest having hooks before any test cases (`prefer-hooks-on-top`)
|
|
2
2
|
|
|
3
3
|
While hooks can be setup anywhere in a test file, they are always called in a
|
|
4
|
-
specific order which means it can be confusing if they're intermixed with test
|
|
4
|
+
specific order, which means it can be confusing if they're intermixed with test
|
|
5
5
|
cases.
|
|
6
6
|
|
|
7
7
|
This rule helps to ensure that hooks are always defined before test cases.
|
|
@@ -73,8 +73,8 @@ it('Uppercase description');
|
|
|
73
73
|
|
|
74
74
|
### `allowedPrefixes`
|
|
75
75
|
|
|
76
|
-
This array option allows specifying prefixes which contain capitals that titles
|
|
77
|
-
can start with. This can be useful when writing tests for
|
|
76
|
+
This array option allows specifying prefixes, which contain capitals that titles
|
|
77
|
+
can start with. This can be useful when writing tests for API endpoints, where
|
|
78
78
|
you'd like to prefix with the HTTP method.
|
|
79
79
|
|
|
80
80
|
By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
|
|
@@ -136,9 +136,9 @@ test('all the things', async () => {
|
|
|
136
136
|
await Promise.resolve(
|
|
137
137
|
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
138
138
|
);
|
|
139
|
-
await Promise.all(
|
|
139
|
+
await Promise.all([
|
|
140
140
|
expect(Promise.resolve('hello')).resolves.toEqual('hello'),
|
|
141
141
|
expect(Promise.resolve('hi')).resolves.toEqual('hi'),
|
|
142
|
-
);
|
|
142
|
+
]);
|
|
143
143
|
});
|
|
144
144
|
```
|
|
@@ -59,6 +59,7 @@ var _default = (0, _utils.createRule)({
|
|
|
59
59
|
|
|
60
60
|
create(context, [mode]) {
|
|
61
61
|
const snapshotMatchers = [];
|
|
62
|
+
const depths = [];
|
|
62
63
|
let expressionDepth = 0;
|
|
63
64
|
|
|
64
65
|
const reportSnapshotMatchersWithoutHints = () => {
|
|
@@ -104,7 +105,21 @@ var _default = (0, _utils.createRule)({
|
|
|
104
105
|
ArrowFunctionExpression: enterExpression,
|
|
105
106
|
'ArrowFunctionExpression:exit': exitExpression,
|
|
106
107
|
|
|
108
|
+
'CallExpression:exit'(node) {
|
|
109
|
+
if ((0, _utils.isDescribeCall)(node) || (0, _utils.isTestCaseCall)(node)) {
|
|
110
|
+
var _depths$pop;
|
|
111
|
+
|
|
112
|
+
/* istanbul ignore next */
|
|
113
|
+
expressionDepth = (_depths$pop = depths.pop()) !== null && _depths$pop !== void 0 ? _depths$pop : 0;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
|
|
107
117
|
CallExpression(node) {
|
|
118
|
+
if ((0, _utils.isDescribeCall)(node) || (0, _utils.isTestCaseCall)(node)) {
|
|
119
|
+
depths.push(expressionDepth);
|
|
120
|
+
expressionDepth = 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
108
123
|
if (!(0, _utils.isExpectCall)(node)) {
|
|
109
124
|
return;
|
|
110
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "26.1.
|
|
3
|
+
"version": "26.1.5",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -111,8 +111,8 @@
|
|
|
111
111
|
"eslint-plugin-import": "^2.25.1",
|
|
112
112
|
"eslint-plugin-node": "^11.0.0",
|
|
113
113
|
"eslint-plugin-prettier": "^3.4.1",
|
|
114
|
-
"eslint-remote-tester": "^2.1.
|
|
115
|
-
"eslint-remote-tester-repositories": "^0.0.
|
|
114
|
+
"eslint-remote-tester": "^2.1.3",
|
|
115
|
+
"eslint-remote-tester-repositories": "^0.0.5",
|
|
116
116
|
"husky": "^7.0.2",
|
|
117
117
|
"is-ci": "^3.0.0",
|
|
118
118
|
"jest": "^27.0.0",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
}
|
|
140
140
|
},
|
|
141
141
|
"engines": {
|
|
142
|
-
"node": "^12.
|
|
142
|
+
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
|
143
143
|
},
|
|
144
144
|
"release": {
|
|
145
145
|
"branches": [
|