eslint-plugin-jest 27.2.1 → 27.2.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 -1
- package/docs/rules/no-alias-methods.md +1 -1
- package/docs/rules/no-hooks.md +1 -1
- package/docs/rules/no-large-snapshots.md +4 -0
- package/docs/rules/require-hook.md +2 -6
- package/docs/rules/valid-expect.md +2 -2
- package/lib/index.js +2 -0
- package/lib/processors/__tests__/snapshot-processor.test.js +36 -0
- package/lib/rules/__tests__/consistent-test-it.test.js +921 -0
- package/lib/rules/__tests__/expect-expect.test.js +347 -0
- package/lib/rules/__tests__/fixtures/class.ts +13 -0
- package/lib/rules/__tests__/fixtures/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/foo.ts +1 -0
- package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +530 -0
- package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +530 -0
- package/lib/rules/__tests__/fixtures/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +6 -0
- package/lib/rules/__tests__/fixtures/tsconfig.json +16 -0
- package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
- package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +15 -0
- package/lib/rules/__tests__/max-expects.test.js +330 -0
- package/lib/rules/__tests__/max-nested-describe.test.js +247 -0
- package/lib/rules/__tests__/no-alias-methods.test.js +190 -0
- package/lib/rules/__tests__/no-commented-out-tests.test.js +213 -0
- package/lib/rules/__tests__/no-conditional-expect.test.js +696 -0
- package/lib/rules/__tests__/no-conditional-in-test.test.js +777 -0
- package/lib/rules/__tests__/no-deprecated-functions.test.js +119 -0
- package/lib/rules/__tests__/no-disabled-tests.test.js +241 -0
- package/lib/rules/__tests__/no-done-callback.test.js +424 -0
- package/lib/rules/__tests__/no-duplicate-hooks.test.js +469 -0
- package/lib/rules/__tests__/no-export.test.js +107 -0
- package/lib/rules/__tests__/no-focused-tests.test.js +373 -0
- package/lib/rules/__tests__/no-hooks.test.js +90 -0
- package/lib/rules/__tests__/no-identical-title.test.js +270 -0
- package/lib/rules/__tests__/no-if.test.js +787 -0
- package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +58 -0
- package/lib/rules/__tests__/no-jasmine-globals.test.js +206 -0
- package/lib/rules/__tests__/no-large-snapshots.test.js +237 -0
- package/lib/rules/__tests__/no-mocks-import.test.js +73 -0
- package/lib/rules/__tests__/no-restricted-jest-methods.test.js +103 -0
- package/lib/rules/__tests__/no-restricted-matchers.test.js +244 -0
- package/lib/rules/__tests__/no-standalone-expect.test.js +230 -0
- package/lib/rules/__tests__/no-test-prefixes.test.js +206 -0
- package/lib/rules/__tests__/no-test-return-statement.test.js +122 -0
- package/lib/rules/__tests__/no-untyped-mock-factory.test.js +149 -0
- package/lib/rules/__tests__/prefer-called-with.test.js +40 -0
- package/lib/rules/__tests__/prefer-comparison-matcher.test.js +200 -0
- package/lib/rules/__tests__/prefer-each.test.js +295 -0
- package/lib/rules/__tests__/prefer-equality-matcher.test.js +184 -0
- package/lib/rules/__tests__/prefer-expect-assertions.test.js +1437 -0
- package/lib/rules/__tests__/prefer-expect-resolves.test.js +96 -0
- package/lib/rules/__tests__/prefer-hooks-in-order.test.js +678 -0
- package/lib/rules/__tests__/prefer-hooks-on-top.test.js +218 -0
- package/lib/rules/__tests__/prefer-lowercase-title.test.js +619 -0
- package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +360 -0
- package/lib/rules/__tests__/prefer-snapshot-hint.test.js +784 -0
- package/lib/rules/__tests__/prefer-spy-on.test.js +100 -0
- package/lib/rules/__tests__/prefer-strict-equal.test.js +46 -0
- package/lib/rules/__tests__/prefer-to-be.test.js +438 -0
- package/lib/rules/__tests__/prefer-to-contain.test.js +301 -0
- package/lib/rules/__tests__/prefer-to-have-length.test.js +99 -0
- package/lib/rules/__tests__/prefer-todo.test.js +78 -0
- package/lib/rules/__tests__/require-hook.test.js +403 -0
- package/lib/rules/__tests__/require-to-throw-message.test.js +108 -0
- package/lib/rules/__tests__/require-top-level-describe.test.js +236 -0
- package/lib/rules/__tests__/test-utils.js +11 -0
- package/lib/rules/__tests__/unbound-method.test.js +518 -0
- package/lib/rules/__tests__/valid-describe-callback.test.js +305 -0
- package/lib/rules/__tests__/valid-expect-in-promise.test.js +1583 -0
- package/lib/rules/__tests__/valid-expect.test.js +894 -0
- package/lib/rules/__tests__/valid-title.test.js +1147 -0
- package/lib/rules/utils/__tests__/detectJestVersion.test.js +221 -0
- package/lib/rules/utils/__tests__/parseJestFnCall.test.js +809 -0
- package/lib/rules/utils/accessors.js +4 -0
- package/lib/rules/utils/misc.js +36 -20
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://eslint.org/">
|
|
3
3
|
<img height="150" src="https://eslint.org/assets/images/logo/eslint-logo-color.svg">
|
|
4
4
|
</a>
|
|
5
|
-
<a href="https://
|
|
5
|
+
<a href="https://jestjs.io/">
|
|
6
6
|
<img width="150" height="150" vspace="" hspace="25" src="https://jestjs.io/img/jest.png">
|
|
7
7
|
</a>
|
|
8
8
|
<h1>eslint-plugin-jest</h1>
|
|
@@ -11,7 +11,7 @@ This rule _warns_ in the 🎨 `style`
|
|
|
11
11
|
<!-- end auto-generated rule header -->
|
|
12
12
|
|
|
13
13
|
> These aliases are going to be removed in the next major version of Jest - see
|
|
14
|
-
> <https://github.com/
|
|
14
|
+
> <https://github.com/jestjs/jest/issues/13164> for more
|
|
15
15
|
|
|
16
16
|
Several Jest methods have alias names, such as `toThrow` having the alias of
|
|
17
17
|
`toThrowError`. This rule ensures that only the canonical name as used in the
|
package/docs/rules/no-hooks.md
CHANGED
|
@@ -24,6 +24,10 @@ module.exports = {
|
|
|
24
24
|
};
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
In order to check external snapshots, you must also have `eslint` check files
|
|
28
|
+
with the `.snap` extension by either passing `--ext snap` on the command line or
|
|
29
|
+
by explicitly specifying `.snap` in `overrides`.
|
|
30
|
+
|
|
27
31
|
## Rule details
|
|
28
32
|
|
|
29
33
|
This rule looks at all Jest inline and external snapshots (files with `.snap`
|
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- end auto-generated rule header -->
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
tests run, and
|
|
7
|
-
run. Jest provides helper functions to handle this.
|
|
8
|
-
|
|
9
|
-
It's common when writing tests to need to perform setup work that needs to
|
|
10
|
-
happen before tests run, and finishing work after tests run.
|
|
5
|
+
It's common when writing tests to need to perform setup work that has to happen
|
|
6
|
+
before tests run, and finishing work after tests run.
|
|
11
7
|
|
|
12
8
|
Because Jest executes all `describe` handlers in a test file _before_ it
|
|
13
9
|
executes any of the actual tests, it's important to ensure setup and teardown
|
|
@@ -66,7 +66,7 @@ This rule is enabled by default.
|
|
|
66
66
|
Enforces to use `await` inside block statements. Using `return` will trigger a
|
|
67
67
|
warning. Returning one line statements with arrow functions is _always allowed_.
|
|
68
68
|
|
|
69
|
-
Examples of **incorrect** code for the { "alwaysAwait":
|
|
69
|
+
Examples of **incorrect** code for the `{ "alwaysAwait": true }` option:
|
|
70
70
|
|
|
71
71
|
```js
|
|
72
72
|
// alwaysAwait: true
|
|
@@ -76,7 +76,7 @@ test('test1', async () => {
|
|
|
76
76
|
});
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Examples of **correct** code for the { "alwaysAwait":
|
|
79
|
+
Examples of **correct** code for the `{ "alwaysAwait": true }` option:
|
|
80
80
|
|
|
81
81
|
```js
|
|
82
82
|
// alwaysAwait: true
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,8 @@ var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-p
|
|
|
7
7
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
8
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
// v5 of `@typescript-eslint/experimental-utils` removed this
|
|
11
|
+
|
|
10
12
|
// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
|
|
11
13
|
/* istanbul ignore next */
|
|
12
14
|
const interopRequireDefault = obj => obj && obj.__esModule ? obj : {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var snapshotProcessor = _interopRequireWildcard(require("../snapshot-processor"));
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
describe('snapshot-processor', () => {
|
|
7
|
+
it('exports an object with preprocess and postprocess functions', () => {
|
|
8
|
+
expect(snapshotProcessor).toMatchObject({
|
|
9
|
+
preprocess: expect.any(Function),
|
|
10
|
+
postprocess: expect.any(Function)
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe('preprocess function', () => {
|
|
14
|
+
it('should pass on untouched source code to source array', () => {
|
|
15
|
+
const {
|
|
16
|
+
preprocess
|
|
17
|
+
} = snapshotProcessor;
|
|
18
|
+
const sourceCode = "const name = 'johnny bravo';";
|
|
19
|
+
const result = preprocess(sourceCode);
|
|
20
|
+
expect(result).toEqual([sourceCode]);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('postprocess function', () => {
|
|
24
|
+
it('should only return messages about snapshot specific rules', () => {
|
|
25
|
+
const {
|
|
26
|
+
postprocess
|
|
27
|
+
} = snapshotProcessor;
|
|
28
|
+
const result = postprocess([['no-console', 'global-require', 'jest/no-large-snapshots'].map(ruleId => ({
|
|
29
|
+
ruleId
|
|
30
|
+
}))]);
|
|
31
|
+
expect(result).toEqual([{
|
|
32
|
+
ruleId: 'jest/no-large-snapshots'
|
|
33
|
+
}]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|