eslint-plugin-jest 26.8.7 β 27.1.6
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 +82 -78
- package/docs/rules/consistent-test-it.md +9 -4
- package/docs/rules/expect-expect.md +5 -0
- package/docs/rules/max-expects.md +3 -1
- package/docs/rules/max-nested-describe.md +3 -1
- package/docs/rules/no-alias-methods.md +13 -2
- package/docs/rules/no-commented-out-tests.md +6 -1
- package/docs/rules/no-conditional-expect.md +7 -2
- package/docs/rules/no-conditional-in-test.md +3 -1
- package/docs/rules/no-deprecated-functions.md +14 -7
- package/docs/rules/no-disabled-tests.md +6 -1
- package/docs/rules/no-done-callback.md +9 -1
- package/docs/rules/no-duplicate-hooks.md +3 -1
- package/docs/rules/no-export.md +6 -1
- package/docs/rules/no-focused-tests.md +10 -1
- package/docs/rules/no-hooks.md +3 -1
- package/docs/rules/no-identical-title.md +6 -1
- package/docs/rules/no-if.md +4 -4
- package/docs/rules/no-interpolation-in-snapshots.md +6 -1
- package/docs/rules/no-jasmine-globals.md +10 -2
- package/docs/rules/no-large-snapshots.md +4 -2
- package/docs/rules/no-mocks-import.md +6 -1
- package/docs/rules/no-restricted-jest-methods.md +51 -0
- package/docs/rules/no-restricted-matchers.md +19 -4
- package/docs/rules/no-standalone-expect.md +6 -1
- package/docs/rules/no-test-prefixes.md +9 -1
- package/docs/rules/no-test-return-statement.md +2 -0
- package/docs/rules/prefer-called-with.md +2 -0
- package/docs/rules/prefer-comparison-matcher.md +5 -0
- package/docs/rules/prefer-each.md +56 -0
- package/docs/rules/prefer-equality-matcher.md +5 -0
- package/docs/rules/prefer-expect-assertions.md +5 -2
- package/docs/rules/prefer-expect-resolves.md +8 -1
- package/docs/rules/prefer-hooks-in-order.md +3 -1
- package/docs/rules/prefer-hooks-on-top.md +3 -1
- package/docs/rules/prefer-lowercase-title.md +5 -0
- package/docs/rules/prefer-mock-promise-shorthand.md +6 -1
- package/docs/rules/prefer-snapshot-hint.md +2 -0
- package/docs/rules/prefer-spy-on.md +5 -2
- package/docs/rules/prefer-strict-equal.md +5 -2
- package/docs/rules/prefer-to-be.md +8 -0
- package/docs/rules/prefer-to-contain.md +8 -2
- package/docs/rules/prefer-to-have-length.md +8 -2
- package/docs/rules/prefer-todo.md +5 -2
- package/docs/rules/require-hook.md +2 -0
- package/docs/rules/require-to-throw-message.md +2 -2
- package/docs/rules/require-top-level-describe.md +5 -1
- package/docs/rules/unbound-method.md +7 -2
- package/docs/rules/valid-describe-callback.md +6 -1
- package/docs/rules/valid-expect-in-promise.md +6 -1
- package/docs/rules/valid-expect.md +5 -2
- package/docs/rules/valid-title.md +9 -1
- package/lib/index.js +14 -25
- package/lib/processors/snapshot-processor.js +3 -5
- package/lib/rules/consistent-test-it.js +1 -19
- package/lib/rules/expect-expect.js +1 -18
- package/lib/rules/max-expects.js +0 -16
- package/lib/rules/max-nested-describe.js +0 -13
- package/lib/rules/no-alias-methods.js +1 -10
- package/lib/rules/no-commented-out-tests.js +0 -10
- package/lib/rules/no-conditional-expect.js +2 -23
- package/lib/rules/no-conditional-in-test.js +0 -9
- package/lib/rules/no-deprecated-functions.js +2 -18
- package/lib/rules/no-disabled-tests.js +3 -19
- package/lib/rules/no-done-callback.js +20 -47
- package/lib/rules/no-duplicate-hooks.js +0 -12
- package/lib/rules/no-export.js +0 -12
- package/lib/rules/no-focused-tests.js +1 -17
- package/lib/rules/no-hooks.js +0 -7
- package/lib/rules/no-identical-title.js +0 -19
- package/lib/rules/no-if.js +0 -24
- package/lib/rules/no-interpolation-in-snapshots.js +0 -9
- package/lib/rules/no-jasmine-globals.js +1 -23
- package/lib/rules/no-large-snapshots.js +4 -24
- package/lib/rules/no-mocks-import.js +0 -12
- package/lib/rules/no-restricted-jest-methods.js +56 -0
- package/lib/rules/no-restricted-matchers.js +13 -28
- package/lib/rules/no-standalone-expect.js +7 -33
- package/lib/rules/no-test-prefixes.js +1 -13
- package/lib/rules/no-test-return-statement.js +0 -12
- package/lib/rules/prefer-called-with.js +0 -10
- package/lib/rules/prefer-comparison-matcher.js +8 -33
- package/lib/rules/prefer-each.js +80 -0
- package/lib/rules/prefer-equality-matcher.js +12 -25
- package/lib/rules/prefer-expect-assertions.js +14 -60
- package/lib/rules/prefer-expect-resolves.js +0 -12
- package/lib/rules/prefer-hooks-in-order.js +2 -16
- package/lib/rules/prefer-hooks-on-top.js +0 -9
- package/lib/rules/prefer-lowercase-title.js +0 -23
- package/lib/rules/prefer-mock-promise-shorthand.js +5 -26
- package/lib/rules/prefer-snapshot-hint.js +8 -34
- package/lib/rules/prefer-spy-on.js +0 -17
- package/lib/rules/prefer-strict-equal.js +1 -11
- package/lib/rules/prefer-to-be.js +12 -37
- package/lib/rules/prefer-to-contain.js +11 -21
- package/lib/rules/prefer-to-have-length.js +4 -16
- package/lib/rules/prefer-todo.js +2 -18
- package/lib/rules/require-hook.js +1 -25
- package/lib/rules/require-to-throw-message.js +0 -9
- package/lib/rules/require-top-level-describe.js +1 -18
- package/lib/rules/unbound-method.js +3 -30
- package/lib/rules/utils/accessors.js +6 -18
- package/lib/rules/utils/detectJestVersion.js +2 -7
- package/lib/rules/utils/followTypeAssertionChain.js +0 -4
- package/lib/rules/utils/index.js +0 -10
- package/lib/rules/utils/misc.js +14 -47
- package/lib/rules/utils/parseJestFnCall.js +51 -154
- package/lib/rules/valid-describe-callback.js +0 -17
- package/lib/rules/valid-expect-in-promise.js +28 -95
- package/lib/rules/valid-expect.js +5 -48
- package/lib/rules/valid-title.js +5 -40
- package/package.json +20 -16
- package/docs/rules/no-jest-import.md +0 -20
- package/lib/rules/no-jest-import.js +0 -48
package/README.md
CHANGED
|
@@ -195,69 +195,85 @@ installations requiring long-term consistency.
|
|
|
195
195
|
|
|
196
196
|
## Rules
|
|
197
197
|
|
|
198
|
-
<!-- begin
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
| [
|
|
216
|
-
| [
|
|
217
|
-
| [
|
|
218
|
-
| [
|
|
219
|
-
| [no-
|
|
220
|
-
| [no-
|
|
221
|
-
| [no-
|
|
222
|
-
| [no-
|
|
223
|
-
| [no-
|
|
224
|
-
| [no-
|
|
225
|
-
| [no-
|
|
226
|
-
| [no-
|
|
227
|
-
| [
|
|
228
|
-
| [
|
|
229
|
-
| [
|
|
230
|
-
| [
|
|
231
|
-
| [
|
|
232
|
-
| [
|
|
233
|
-
| [
|
|
234
|
-
| [
|
|
235
|
-
| [
|
|
236
|
-
| [
|
|
237
|
-
| [
|
|
238
|
-
| [
|
|
239
|
-
| [
|
|
240
|
-
| [
|
|
241
|
-
| [prefer-
|
|
242
|
-
| [prefer-
|
|
243
|
-
| [
|
|
244
|
-
| [
|
|
245
|
-
| [
|
|
246
|
-
| [
|
|
247
|
-
| [
|
|
248
|
-
| [
|
|
249
|
-
| [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
[
|
|
198
|
+
<!-- begin auto-generated rules list -->
|
|
199
|
+
|
|
200
|
+
πΌ
|
|
201
|
+
[Configurations](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations)
|
|
202
|
+
enabled in.\
|
|
203
|
+
β οΈ [Configurations](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations)
|
|
204
|
+
set to warn in.\
|
|
205
|
+
β
Set in the `recommended`
|
|
206
|
+
[configuration](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).\
|
|
207
|
+
π¨ Set in the `style` [configuration](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).\
|
|
208
|
+
π§ Automatically fixable by the
|
|
209
|
+
[`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
210
|
+
π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).\
|
|
211
|
+
β Deprecated.
|
|
212
|
+
|
|
213
|
+
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π§ | π‘ | β |
|
|
214
|
+
| :--------------------------------------------------------------------------- | :------------------------------------------------------------------ | :-- | :-- | :-- | :-- | :-- |
|
|
215
|
+
| [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce `test` and `it` usage conventions | | | π§ | | |
|
|
216
|
+
| [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | | β
| | | |
|
|
217
|
+
| [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | | | | |
|
|
218
|
+
| [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | | | | |
|
|
219
|
+
| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | β
| π¨ | π§ | | |
|
|
220
|
+
| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | | β
| | | |
|
|
221
|
+
| [no-conditional-expect](docs/rules/no-conditional-expect.md) | Disallow calling `expect` conditionally | β
| | | | |
|
|
222
|
+
| [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | | | | |
|
|
223
|
+
| [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | β
| | π§ | | |
|
|
224
|
+
| [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | | β
| | | |
|
|
225
|
+
| [no-done-callback](docs/rules/no-done-callback.md) | Disallow using a callback in asynchronous tests and hooks | β
| | | π‘ | |
|
|
226
|
+
| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | | | | |
|
|
227
|
+
| [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests | β
| | | | |
|
|
228
|
+
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | β
| | | π‘ | |
|
|
229
|
+
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | | | |
|
|
230
|
+
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | β
| | | | |
|
|
231
|
+
| [no-if](docs/rules/no-if.md) | Disallow conditional logic | | | | | β |
|
|
232
|
+
| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | β
| | | | |
|
|
233
|
+
| [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | β
| | π§ | | |
|
|
234
|
+
| [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | | | |
|
|
235
|
+
| [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | β
| | | | |
|
|
236
|
+
| [no-restricted-jest-methods](docs/rules/no-restricted-jest-methods.md) | Disallow specific `jest.` methods | | | | | |
|
|
237
|
+
| [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | | | | |
|
|
238
|
+
| [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks | β
| | | | |
|
|
239
|
+
| [no-test-prefixes](docs/rules/no-test-prefixes.md) | Require using `.only` and `.skip` over `f` and `x` | β
| | π§ | | |
|
|
240
|
+
| [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | | | | |
|
|
241
|
+
| [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | | | | |
|
|
242
|
+
| [prefer-comparison-matcher](docs/rules/prefer-comparison-matcher.md) | Suggest using the built-in comparison matchers | | | π§ | | |
|
|
243
|
+
| [prefer-each](docs/rules/prefer-each.md) | Prefer using `.each` rather than manual loops | | | | | |
|
|
244
|
+
| [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | | | π‘ | |
|
|
245
|
+
| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | | | π‘ | |
|
|
246
|
+
| [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | Prefer `await expect(...).resolves` over `expect(await ...)` syntax | | | π§ | | |
|
|
247
|
+
| [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | | | | |
|
|
248
|
+
| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | | | | |
|
|
249
|
+
| [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | | π§ | | |
|
|
250
|
+
| [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | Prefer mock resolved/rejected shorthands for promises | | | π§ | | |
|
|
251
|
+
| [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | Prefer including a hint with external snapshots | | | | | |
|
|
252
|
+
| [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | | π§ | | |
|
|
253
|
+
| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | | | π‘ | |
|
|
254
|
+
| [prefer-to-be](docs/rules/prefer-to-be.md) | Suggest using `toBe()` for primitive literals | π¨ | | π§ | | |
|
|
255
|
+
| [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | π¨ | | π§ | | |
|
|
256
|
+
| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | π¨ | | π§ | | |
|
|
257
|
+
| [prefer-todo](docs/rules/prefer-todo.md) | Suggest using `test.todo` | | | π§ | | |
|
|
258
|
+
| [require-hook](docs/rules/require-hook.md) | Require setup and teardown code to be within a hook | | | | | |
|
|
259
|
+
| [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | | | | |
|
|
260
|
+
| [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | | | | |
|
|
261
|
+
| [valid-describe-callback](docs/rules/valid-describe-callback.md) | Enforce valid `describe()` callback | β
| | | | |
|
|
262
|
+
| [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | β
| | | | |
|
|
263
|
+
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Require promises that have expectations in their chain to be valid | β
| | | | |
|
|
264
|
+
| [valid-title](docs/rules/valid-title.md) | Enforce valid titles | β
| | π§ | | |
|
|
265
|
+
|
|
266
|
+
### Requires Type Checking
|
|
267
|
+
|
|
268
|
+
| NameΒ Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π§ | π‘ | β |
|
|
269
|
+
| :--------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- | :-- |
|
|
270
|
+
| [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | | | | |
|
|
271
|
+
|
|
272
|
+
<!-- end auto-generated rules list -->
|
|
273
|
+
|
|
274
|
+
In order to use the rules powered by TypeScript type-checking, you must be using
|
|
275
|
+
`@typescript-eslint/parser` & adjust your eslint config as outlined
|
|
276
|
+
[here](https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TYPED_LINTING.md).
|
|
261
277
|
|
|
262
278
|
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
263
279
|
the rules here will fallback to doing nothing if type information is not
|
|
@@ -267,14 +283,6 @@ used on JavaScript and TypeScript projects.
|
|
|
267
283
|
Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
|
|
268
284
|
as it extends the original `unbound-method` rule from that plugin.
|
|
269
285
|
|
|
270
|
-
<!-- begin type rules list -->
|
|
271
|
-
|
|
272
|
-
| Rule | Description | Configurations | Fixable |
|
|
273
|
-
| ---------------------------------------------- | ------------------------------------------------------------ | -------------- | ------- |
|
|
274
|
-
| [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | |
|
|
275
|
-
|
|
276
|
-
<!-- end type rules list -->
|
|
277
|
-
|
|
278
286
|
## Credit
|
|
279
287
|
|
|
280
288
|
- [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha)
|
|
@@ -288,24 +296,20 @@ This is a sister plugin to `eslint-plugin-jest` that provides support for the
|
|
|
288
296
|
matchers provided by
|
|
289
297
|
[`jest-extended`](https://github.com/jest-community/jest-extended).
|
|
290
298
|
|
|
291
|
-
https://github.com/jest-community/eslint-plugin-jest-extended
|
|
299
|
+
<https://github.com/jest-community/eslint-plugin-jest-extended>
|
|
292
300
|
|
|
293
301
|
### eslint-plugin-jest-formatting
|
|
294
302
|
|
|
295
303
|
This project aims to provide formatting rules (auto-fixable where possible) to
|
|
296
304
|
ensure consistency and readability in jest test suites.
|
|
297
305
|
|
|
298
|
-
https://github.com/dangreenisrael/eslint-plugin-jest-formatting
|
|
306
|
+
<https://github.com/dangreenisrael/eslint-plugin-jest-formatting>
|
|
299
307
|
|
|
300
308
|
### eslint-plugin-istanbul
|
|
301
309
|
|
|
302
310
|
A set of rules to enforce good practices for Istanbul, one of the code coverage
|
|
303
311
|
tools used by Jest.
|
|
304
312
|
|
|
305
|
-
https://github.com/istanbuljs/eslint-plugin-istanbul
|
|
313
|
+
<https://github.com/istanbuljs/eslint-plugin-istanbul>
|
|
306
314
|
|
|
307
|
-
[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
|
|
308
|
-
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
|
|
309
|
-
[fixable]: https://img.shields.io/badge/-fixable-green.svg
|
|
310
|
-
[style]: https://img.shields.io/badge/-style-blue.svg
|
|
311
315
|
[`no-deprecated-functions`]: docs/rules/no-deprecated-functions.md
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Enforce `test` and `it` usage conventions (`consistent-test-it`)
|
|
2
|
+
|
|
3
|
+
π§ This rule is automatically fixable by the
|
|
4
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
2
7
|
|
|
3
8
|
Jest allows you to choose how you want to define your tests, using the `it` or
|
|
4
9
|
the `test` keywords, with multiple permutations for each:
|
|
@@ -6,9 +11,11 @@ the `test` keywords, with multiple permutations for each:
|
|
|
6
11
|
- **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
|
|
7
12
|
- **test:** `test`, `xtest`, `test.only`, `test.skip`.
|
|
8
13
|
|
|
14
|
+
## Rule details
|
|
15
|
+
|
|
9
16
|
This rule gives you control over the usage of these keywords in your codebase.
|
|
10
17
|
|
|
11
|
-
##
|
|
18
|
+
## Options
|
|
12
19
|
|
|
13
20
|
This rule can be configured as follows
|
|
14
21
|
|
|
@@ -69,8 +76,6 @@ describe('foo', function () {
|
|
|
69
76
|
});
|
|
70
77
|
```
|
|
71
78
|
|
|
72
|
-
### Default configuration
|
|
73
|
-
|
|
74
79
|
The default configuration forces all top-level tests to use `test` and all tests
|
|
75
80
|
nested within `describe` to use `it`.
|
|
76
81
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Enforce assertion to be made in a test body (`expect-expect`)
|
|
2
2
|
|
|
3
|
+
β οΈ This rule _warns_ in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
Ensure that there is at least one `expect` call made in a test.
|
|
4
9
|
|
|
5
10
|
## Rule details
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Enforces a maximum number assertion calls in a test body (`max-expects`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
3
5
|
As more assertions are made, there is a possible tendency for the test to be
|
|
4
6
|
more likely to mix multiple objectives. To avoid this, this rule reports when
|
|
5
7
|
the maximum number of assertions is exceeded.
|
|
6
8
|
|
|
7
|
-
## Rule
|
|
9
|
+
## Rule details
|
|
8
10
|
|
|
9
11
|
This rule enforces a maximum number of `expect()` calls.
|
|
10
12
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
3
5
|
While it's useful to be able to group your tests together within the same file
|
|
4
6
|
using `describe()`, having too many levels of nesting throughout your tests make
|
|
5
7
|
them difficult to read.
|
|
6
8
|
|
|
7
|
-
## Rule
|
|
9
|
+
## Rule details
|
|
8
10
|
|
|
9
11
|
This rule enforces a maximum depth to nested `describe()` calls to improve code
|
|
10
12
|
clarity in your tests.
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Disallow alias methods (`no-alias-methods`)
|
|
2
2
|
|
|
3
|
+
πΌβ οΈ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
This rule _warns_ in the π¨ `style`
|
|
6
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
7
|
+
|
|
8
|
+
π§ This rule is automatically fixable by the
|
|
9
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
10
|
+
|
|
11
|
+
<!-- end auto-generated rule header -->
|
|
12
|
+
|
|
13
|
+
> These aliases are going to be removed in the next major version of Jest - see
|
|
14
|
+
> <https://github.com/facebook/jest/issues/13164> for more
|
|
15
|
+
|
|
3
16
|
Several Jest methods have alias names, such as `toThrow` having the alias of
|
|
4
17
|
`toThrowError`. This rule ensures that only the canonical name as used in the
|
|
5
18
|
Jest documentation is used in the code. This makes it easier to search for all
|
|
@@ -11,8 +24,6 @@ method names used.
|
|
|
11
24
|
This rule triggers a warning if the alias name, rather than the canonical name,
|
|
12
25
|
of a method is used.
|
|
13
26
|
|
|
14
|
-
### Default configuration
|
|
15
|
-
|
|
16
27
|
The following patterns are considered warnings:
|
|
17
28
|
|
|
18
29
|
```js
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# Disallow commented out tests (`no-commented-out-tests`)
|
|
2
2
|
|
|
3
|
+
β οΈ This rule _warns_ in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
This rule raises a warning about commented out tests. It's similar to
|
|
4
9
|
no-disabled-tests rule.
|
|
5
10
|
|
|
6
|
-
## Rule
|
|
11
|
+
## Rule details
|
|
7
12
|
|
|
8
13
|
The rule uses fuzzy matching to do its best to determine what constitutes a
|
|
9
14
|
commented out test, checking for a presence of `it(`, `describe(`, `it.skip(`,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow calling `expect` conditionally (`no-conditional-expect`)
|
|
2
|
+
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
2
7
|
|
|
3
8
|
This rule prevents the use of `expect` in conditional blocks, such as `if`s &
|
|
4
9
|
`catch`s.
|
|
@@ -6,7 +11,7 @@ This rule prevents the use of `expect` in conditional blocks, such as `if`s &
|
|
|
6
11
|
This includes using `expect` in callbacks to functions named `catch`, which are
|
|
7
12
|
assumed to be promises.
|
|
8
13
|
|
|
9
|
-
## Rule
|
|
14
|
+
## Rule details
|
|
10
15
|
|
|
11
16
|
Jest only considers a test to have failed if it throws an error, meaning if
|
|
12
17
|
calls to assertion functions like `expect` occur in conditional code such as a
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Disallow conditional logic in tests (`no-conditional-in-test`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
3
5
|
Conditional logic in tests is usually an indication that a test is attempting to
|
|
4
6
|
cover too much, and not testing the logic it intends to. Each branch of code
|
|
5
7
|
executing within a conditional statement will usually be better served by a test
|
|
6
8
|
devoted to it.
|
|
7
9
|
|
|
8
|
-
## Rule
|
|
10
|
+
## Rule details
|
|
9
11
|
|
|
10
12
|
This rule reports on any use of a conditional statement such as `if`, `switch`,
|
|
11
13
|
and ternary expressions.
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Disallow use of deprecated functions (`no-deprecated-functions`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
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
|
+
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
10
|
+
|
|
3
11
|
Over the years Jest has accrued some debt in the form of functions that have
|
|
4
12
|
either been renamed for clarity, or replaced with more powerful APIs.
|
|
5
13
|
|
|
@@ -20,13 +28,12 @@ This rule can also autofix a number of these deprecations for you.
|
|
|
20
28
|
|
|
21
29
|
### `jest.resetModuleRegistry`
|
|
22
30
|
|
|
23
|
-
This function was renamed to `resetModules` in Jest 15
|
|
24
|
-
removal in Jest 27.
|
|
31
|
+
This function was renamed to `resetModules` in Jest 15 and removed in Jest 27.
|
|
25
32
|
|
|
26
33
|
### `jest.addMatchers`
|
|
27
34
|
|
|
28
|
-
This function was replaced with `expect.extend` in Jest 17
|
|
29
|
-
|
|
35
|
+
This function was replaced with `expect.extend` in Jest 17 and removed in
|
|
36
|
+
Jest 27.
|
|
30
37
|
|
|
31
38
|
### `require.requireActual` & `require.requireMock`
|
|
32
39
|
|
|
@@ -41,10 +48,10 @@ the release of Jest 26 saw them removed from the `require` function altogether.
|
|
|
41
48
|
|
|
42
49
|
### `jest.runTimersToTime`
|
|
43
50
|
|
|
44
|
-
This function was renamed to `advanceTimersByTime` in Jest 22
|
|
45
|
-
|
|
51
|
+
This function was renamed to `advanceTimersByTime` in Jest 22 and removed in
|
|
52
|
+
Jest 27.
|
|
46
53
|
|
|
47
54
|
### `jest.genMockFromModule`
|
|
48
55
|
|
|
49
56
|
This function was renamed to `createMockFromModule` in Jest 26, and is scheduled
|
|
50
|
-
for removal in
|
|
57
|
+
for removal in Jest 30.
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Disallow disabled tests (`no-disabled-tests`)
|
|
2
2
|
|
|
3
|
+
β οΈ This rule _warns_ in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
Jest has a feature that allows you to temporarily mark tests as disabled. This
|
|
4
9
|
feature is often helpful while debugging or to create placeholders for future
|
|
5
10
|
tests. Before committing changes we may want to check that all tests are
|
|
@@ -7,7 +12,7 @@ running.
|
|
|
7
12
|
|
|
8
13
|
This rule raises a warning about disabled tests.
|
|
9
14
|
|
|
10
|
-
## Rule
|
|
15
|
+
## Rule details
|
|
11
16
|
|
|
12
17
|
There are a number of ways to disable tests in Jest:
|
|
13
18
|
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using a callback in asynchronous tests and hooks (`no-done-callback`)
|
|
2
|
+
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
π‘ This rule is manually fixable by
|
|
7
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
8
|
+
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
2
10
|
|
|
3
11
|
When calling asynchronous code in hooks and tests, `jest` needs to know when the
|
|
4
12
|
asynchronous work is complete to progress the current run.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
3
5
|
A `describe` block should not contain duplicate hooks.
|
|
4
6
|
|
|
5
|
-
## Rule
|
|
7
|
+
## Rule details
|
|
6
8
|
|
|
7
9
|
Examples of **incorrect** code for this rule
|
|
8
10
|
|
package/docs/rules/no-export.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Disallow using `exports` in files containing tests (`no-export`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
Prevents using `exports` if a file has one or more tests in it.
|
|
4
9
|
|
|
5
|
-
## Rule
|
|
10
|
+
## Rule details
|
|
6
11
|
|
|
7
12
|
This rule aims to eliminate duplicate runs of tests by exporting things from
|
|
8
13
|
test files. If you import from a test file, then all the tests in that file will
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Disallow focused tests (`no-focused-tests`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
π‘ This rule is manually fixable by
|
|
7
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
8
|
+
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
10
|
+
|
|
11
|
+
<!-- prettier-ignore -->
|
|
3
12
|
Jest has a feature that allows you to focus tests by appending `.only` or
|
|
4
13
|
prepending `f` to a test-suite or a test-case. This feature is really helpful to
|
|
5
14
|
debug a failing test, so you donβt have to execute all of your tests. After you
|
|
@@ -9,7 +18,7 @@ have fixed your test and before committing the changes you have to remove
|
|
|
9
18
|
This rule reminds you to remove `.only` from your tests by raising a warning
|
|
10
19
|
whenever you are using the exclusivity feature.
|
|
11
20
|
|
|
12
|
-
## Rule
|
|
21
|
+
## Rule details
|
|
13
22
|
|
|
14
23
|
This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
|
|
15
24
|
and `fit` occurrences within the source code. Of course there are some
|
package/docs/rules/no-hooks.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Disallow setup and teardown hooks (`no-hooks`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
3
5
|
Jest provides global functions for setup and teardown tasks, which are called
|
|
4
6
|
before/after each test case and each test suite. The use of these hooks promotes
|
|
5
7
|
shared state between tests.
|
|
6
8
|
|
|
7
|
-
## Rule
|
|
9
|
+
## Rule details
|
|
8
10
|
|
|
9
11
|
This rule reports for the following function calls:
|
|
10
12
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# Disallow identical titles (`no-identical-title`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
Having identical titles for two different tests or test suites may create
|
|
4
9
|
confusion. For example, when a test with the same title as another test in the
|
|
5
10
|
same test suite fails, it is harder to know which one failed and thus harder to
|
|
6
11
|
fix.
|
|
7
12
|
|
|
8
|
-
## Rule
|
|
13
|
+
## Rule details
|
|
9
14
|
|
|
10
15
|
This rule looks at the title of every test and test suite. It will report when
|
|
11
16
|
two test suites or two test cases at the same level of a test suite have the
|
package/docs/rules/no-if.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Disallow conditional logic (`no-if`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This rule has been deprecated in favor of
|
|
3
|
+
β This rule is deprecated. It was replaced by
|
|
6
4
|
[`no-conditional-in-test`](no-conditional-in-test.md).
|
|
7
5
|
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
8
8
|
Conditional logic in tests is usually an indication that a test is attempting to
|
|
9
9
|
cover too much, and not testing the logic it intends to. Each branch of code
|
|
10
10
|
executing within an if statement will usually be better served by a test devoted
|
|
@@ -13,7 +13,7 @@ to it.
|
|
|
13
13
|
Conditionals are often used to satisfy the typescript type checker. In these
|
|
14
14
|
cases, using the non-null assertion operator (!) would be best.
|
|
15
15
|
|
|
16
|
-
## Rule
|
|
16
|
+
## Rule details
|
|
17
17
|
|
|
18
18
|
This rule prevents the use of if/ else statements and conditional (ternary)
|
|
19
19
|
operations in tests.
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
5
|
+
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
|
+
|
|
3
8
|
Prevents the use of string interpolations in snapshots.
|
|
4
9
|
|
|
5
|
-
## Rule
|
|
10
|
+
## Rule details
|
|
6
11
|
|
|
7
12
|
Interpolation prevents snapshots from being updated. Instead, properties should
|
|
8
13
|
be overloaded with a matcher by using
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Disallow Jasmine globals (`no-jasmine-globals`)
|
|
2
2
|
|
|
3
|
+
πΌ This rule is enabled in the β
`recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
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
|
+
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
10
|
+
|
|
3
11
|
`jest` uses `jasmine` as a test runner. A side effect of this is that both a
|
|
4
12
|
`jasmine` object, and some jasmine-specific globals, are exposed to the test
|
|
5
13
|
environment. Most functionality offered by Jasmine has been ported to Jest, and
|
|
@@ -7,12 +15,12 @@ the Jasmine globals will stop working in the future. Developers should therefore
|
|
|
7
15
|
migrate to Jest's documented API instead of relying on the undocumented Jasmine
|
|
8
16
|
API.
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
## Rule details
|
|
11
19
|
|
|
12
20
|
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
|
|
13
21
|
and suggests alternatives from Jest's own API.
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
## Examples
|
|
16
24
|
|
|
17
25
|
The following patterns are considered warnings:
|
|
18
26
|
|