eslint-plugin-jest 27.0.0-next.1 → 27.0.0-next.2
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 +1 -2
- package/docs/rules/no-alias-methods.md +3 -0
- package/docs/rules/no-restricted-matchers.md +12 -3
- package/lib/rules/no-alias-methods.js +1 -1
- package/lib/rules/no-restricted-matchers.js +7 -19
- package/lib/rules/unbound-method.js +1 -9
- package/package.json +11 -11
- package/docs/rules/no-jest-import.md +0 -20
- package/lib/rules/no-jest-import.js +0 -48
package/README.md
CHANGED
|
@@ -203,7 +203,7 @@ installations requiring long-term consistency.
|
|
|
203
203
|
| [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | |
|
|
204
204
|
| [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | |
|
|
205
205
|
| [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | |
|
|
206
|
-
| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods |  | Disallow alias methods | ![recommended][] | ![fixable][] |
|
|
207
207
|
| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
|
|
208
208
|
| [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
|
|
209
209
|
| [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | |
|
|
@@ -217,7 +217,6 @@ installations requiring long-term consistency.
|
|
|
217
217
|
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
|
|
218
218
|
| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | |
|
|
219
219
|
| [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] |
|
|
220
|
-
| [no-jest-import](docs/rules/no-jest-import.md) | Disallow importing Jest | ![recommended][] | |
|
|
221
220
|
| [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
|
|
222
221
|
| [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ![recommended][] | |
|
|
223
222
|
| [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | |
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Disallow alias methods (`no-alias-methods`)
|
|
2
2
|
|
|
3
|
+
> These aliases are going to be removed in the next major version of Jest - see
|
|
4
|
+
> https://github.com/facebook/jest/issues/13164 for more
|
|
5
|
+
|
|
3
6
|
Several Jest methods have alias names, such as `toThrow` having the alias of
|
|
4
7
|
`toThrowError`. This rule ensures that only the canonical name as used in the
|
|
5
8
|
Jest documentation is used in the code. This makes it easier to search for all
|
|
@@ -8,8 +8,9 @@ alternatives.
|
|
|
8
8
|
Bans are expressed in the form of a map, with the value being either a string
|
|
9
9
|
message to be shown, or `null` if the default rule message should be used.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
specific
|
|
11
|
+
Bans are checked against the start of the `expect` chain - this means that to
|
|
12
|
+
ban a specific matcher entirely you must specify all six permutations, but
|
|
13
|
+
allows you to ban modifiers as well.
|
|
13
14
|
|
|
14
15
|
By default, this map is empty, meaning no matchers or modifiers are banned.
|
|
15
16
|
|
|
@@ -22,7 +23,12 @@ For example:
|
|
|
22
23
|
{
|
|
23
24
|
"toBeFalsy": null,
|
|
24
25
|
"resolves": "Use `expect(await promise)` instead.",
|
|
25
|
-
"
|
|
26
|
+
"toHaveBeenCalledWith": null,
|
|
27
|
+
"not.toHaveBeenCalledWith": null,
|
|
28
|
+
"resolves.toHaveBeenCalledWith": null,
|
|
29
|
+
"rejects.toHaveBeenCalledWith": null,
|
|
30
|
+
"resolves.not.toHaveBeenCalledWith": null,
|
|
31
|
+
"rejects.not.toHaveBeenCalledWith": null
|
|
26
32
|
}
|
|
27
33
|
]
|
|
28
34
|
}
|
|
@@ -32,15 +38,18 @@ Examples of **incorrect** code for this rule with the above configuration
|
|
|
32
38
|
|
|
33
39
|
```js
|
|
34
40
|
it('is false', () => {
|
|
41
|
+
// if this has a modifer (i.e. `not.toBeFalsy`), it would be considered fine
|
|
35
42
|
expect(a).toBeFalsy();
|
|
36
43
|
});
|
|
37
44
|
|
|
38
45
|
it('resolves', async () => {
|
|
46
|
+
// all uses of this modifier are disallowed, regardless of matcher
|
|
39
47
|
await expect(myPromise()).resolves.toBe(true);
|
|
40
48
|
});
|
|
41
49
|
|
|
42
50
|
describe('when an error happens', () => {
|
|
43
51
|
it('does not upload the file', async () => {
|
|
52
|
+
// all uses of this matcher are disallowed
|
|
44
53
|
expect(uploadFileMock).not.toHaveBeenCalledWith('file.name');
|
|
45
54
|
});
|
|
46
55
|
});
|
|
@@ -13,7 +13,7 @@ var _default = (0, _utils.createRule)({
|
|
|
13
13
|
docs: {
|
|
14
14
|
category: 'Best Practices',
|
|
15
15
|
description: 'Disallow alias methods',
|
|
16
|
-
recommended:
|
|
16
|
+
recommended: 'error'
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
|
19
19
|
replaceAlias: `Replace {{ alias }}() with its canonical name of {{ canonical }}()`
|
|
@@ -23,7 +23,7 @@ var _default = (0, _utils.createRule)({
|
|
|
23
23
|
}
|
|
24
24
|
}],
|
|
25
25
|
messages: {
|
|
26
|
-
restrictedChain: 'Use of `{{
|
|
26
|
+
restrictedChain: 'Use of `{{ restriction }}` is disallowed',
|
|
27
27
|
restrictedChainWithMessage: '{{ message }}'
|
|
28
28
|
}
|
|
29
29
|
},
|
|
@@ -38,31 +38,19 @@ var _default = (0, _utils.createRule)({
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const chain = jestFnCall.members.map(nod => (0, _utils.getAccessorValue)(nod)).join('.');
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
permutations.push([jestFnCall.members[1], jestFnCall.members[2]]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (jestFnCall.members.length > 1) {
|
|
49
|
-
permutations.push(...jestFnCall.members.map(nod => [nod]));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (const permutation of permutations) {
|
|
53
|
-
const chain = permutation.map(nod => (0, _utils.getAccessorValue)(nod)).join('.');
|
|
54
|
-
|
|
55
|
-
if (chain in restrictedChains) {
|
|
56
|
-
const message = restrictedChains[chain];
|
|
43
|
+
for (const [restriction, message] of Object.entries(restrictedChains)) {
|
|
44
|
+
if (chain.startsWith(restriction)) {
|
|
57
45
|
context.report({
|
|
58
46
|
messageId: message ? 'restrictedChainWithMessage' : 'restrictedChain',
|
|
59
47
|
data: {
|
|
60
48
|
message,
|
|
61
|
-
|
|
49
|
+
restriction
|
|
62
50
|
},
|
|
63
51
|
loc: {
|
|
64
|
-
start:
|
|
65
|
-
end:
|
|
52
|
+
start: jestFnCall.members[0].loc.start,
|
|
53
|
+
end: jestFnCall.members[jestFnCall.members.length - 1].loc.end
|
|
66
54
|
}
|
|
67
55
|
});
|
|
68
56
|
break;
|
|
@@ -28,14 +28,6 @@ const baseRule = (() => {
|
|
|
28
28
|
}
|
|
29
29
|
})();
|
|
30
30
|
|
|
31
|
-
const tryCreateBaseRule = context => {
|
|
32
|
-
try {
|
|
33
|
-
return baseRule === null || baseRule === void 0 ? void 0 : baseRule.create(context);
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
31
|
const DEFAULT_MESSAGE = 'This rule requires `@typescript-eslint/eslint-plugin`';
|
|
40
32
|
|
|
41
33
|
var _default = (0, _utils2.createRule)({
|
|
@@ -62,7 +54,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
62
54
|
},
|
|
63
55
|
|
|
64
56
|
create(context) {
|
|
65
|
-
const baseSelectors =
|
|
57
|
+
const baseSelectors = baseRule === null || baseRule === void 0 ? void 0 : baseRule.create(context);
|
|
66
58
|
|
|
67
59
|
if (!baseSelectors) {
|
|
68
60
|
return {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "27.0.0-next.
|
|
3
|
+
"version": "27.0.0-next.2",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -103,34 +103,34 @@
|
|
|
103
103
|
"@babel/core": "^7.4.4",
|
|
104
104
|
"@babel/preset-env": "^7.4.4",
|
|
105
105
|
"@babel/preset-typescript": "^7.3.3",
|
|
106
|
-
"@commitlint/cli": "^
|
|
107
|
-
"@commitlint/config-conventional": "^
|
|
106
|
+
"@commitlint/cli": "^17.0.3",
|
|
107
|
+
"@commitlint/config-conventional": "^17.0.3",
|
|
108
108
|
"@schemastore/package": "^0.0.6",
|
|
109
109
|
"@semantic-release/changelog": "^6.0.0",
|
|
110
110
|
"@semantic-release/git": "^10.0.0",
|
|
111
111
|
"@types/dedent": "^0.7.0",
|
|
112
112
|
"@types/jest": "^28.0.0",
|
|
113
|
-
"@types/node": "^
|
|
113
|
+
"@types/node": "^14.18.26",
|
|
114
114
|
"@types/prettier": "^2.0.0",
|
|
115
115
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
116
116
|
"@typescript-eslint/parser": "^5.0.0",
|
|
117
|
-
"babel-jest": "^
|
|
117
|
+
"babel-jest": "^29.0.0",
|
|
118
118
|
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
|
|
119
119
|
"dedent": "^0.7.0",
|
|
120
120
|
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
121
121
|
"eslint-config-prettier": "^8.3.0",
|
|
122
122
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
123
|
-
"eslint-plugin-eslint-plugin": "^
|
|
123
|
+
"eslint-plugin-eslint-plugin": "^5.0.6",
|
|
124
124
|
"eslint-plugin-import": "^2.25.1",
|
|
125
125
|
"eslint-plugin-node": "^11.0.0",
|
|
126
|
-
"eslint-plugin-prettier": "^
|
|
126
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
127
127
|
"eslint-remote-tester": "^3.0.0",
|
|
128
128
|
"eslint-remote-tester-repositories": "~0.0.5",
|
|
129
|
-
"husky": "^
|
|
129
|
+
"husky": "^8.0.1",
|
|
130
130
|
"is-ci": "^3.0.0",
|
|
131
|
-
"jest": "^
|
|
132
|
-
"jest-runner-eslint": "^1.
|
|
133
|
-
"lint-staged": "^
|
|
131
|
+
"jest": "^29.0.0",
|
|
132
|
+
"jest-runner-eslint": "^1.1.0",
|
|
133
|
+
"lint-staged": "^13.0.3",
|
|
134
134
|
"pinst": "^3.0.0",
|
|
135
135
|
"prettier": "^2.0.5",
|
|
136
136
|
"rimraf": "^3.0.0",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Disallow importing Jest (`no-jest-import`)
|
|
2
|
-
|
|
3
|
-
The `jest` object is automatically in scope within every test file. The methods
|
|
4
|
-
in the `jest` object help create mocks and let you control Jest's overall
|
|
5
|
-
behavior. It is therefore completely unnecessary to import in `jest`, as Jest
|
|
6
|
-
doesn't export anything in the first place.
|
|
7
|
-
|
|
8
|
-
### Rule details
|
|
9
|
-
|
|
10
|
-
This rule reports on any importing of Jest.
|
|
11
|
-
|
|
12
|
-
To name a few: `var jest = require('jest');` `const jest = require('jest');`
|
|
13
|
-
`import jest from 'jest';` `import {jest as test} from 'jest';`
|
|
14
|
-
|
|
15
|
-
There is no correct usage of this code, other than to not import `jest` in the
|
|
16
|
-
first place.
|
|
17
|
-
|
|
18
|
-
## Further Reading
|
|
19
|
-
|
|
20
|
-
- [The Jest Object](https://facebook.github.io/jest/docs/en/jest-object.html)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _utils.createRule)({
|
|
11
|
-
name: __filename,
|
|
12
|
-
meta: {
|
|
13
|
-
type: 'problem',
|
|
14
|
-
docs: {
|
|
15
|
-
description: 'Disallow importing Jest',
|
|
16
|
-
category: 'Best Practices',
|
|
17
|
-
recommended: 'error'
|
|
18
|
-
},
|
|
19
|
-
messages: {
|
|
20
|
-
unexpectedImport: `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`
|
|
21
|
-
},
|
|
22
|
-
schema: []
|
|
23
|
-
},
|
|
24
|
-
defaultOptions: [],
|
|
25
|
-
|
|
26
|
-
create(context) {
|
|
27
|
-
return {
|
|
28
|
-
'ImportDeclaration[source.value="jest"]'(node) {
|
|
29
|
-
context.report({
|
|
30
|
-
node,
|
|
31
|
-
messageId: 'unexpectedImport'
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
'CallExpression[callee.name="require"][arguments.0.value="jest"]'(node) {
|
|
36
|
-
context.report({
|
|
37
|
-
loc: node.arguments[0].loc,
|
|
38
|
-
messageId: 'unexpectedImport',
|
|
39
|
-
node
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
exports.default = _default;
|