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.
Files changed (114) hide show
  1. package/README.md +82 -78
  2. package/docs/rules/consistent-test-it.md +9 -4
  3. package/docs/rules/expect-expect.md +5 -0
  4. package/docs/rules/max-expects.md +3 -1
  5. package/docs/rules/max-nested-describe.md +3 -1
  6. package/docs/rules/no-alias-methods.md +13 -2
  7. package/docs/rules/no-commented-out-tests.md +6 -1
  8. package/docs/rules/no-conditional-expect.md +7 -2
  9. package/docs/rules/no-conditional-in-test.md +3 -1
  10. package/docs/rules/no-deprecated-functions.md +14 -7
  11. package/docs/rules/no-disabled-tests.md +6 -1
  12. package/docs/rules/no-done-callback.md +9 -1
  13. package/docs/rules/no-duplicate-hooks.md +3 -1
  14. package/docs/rules/no-export.md +6 -1
  15. package/docs/rules/no-focused-tests.md +10 -1
  16. package/docs/rules/no-hooks.md +3 -1
  17. package/docs/rules/no-identical-title.md +6 -1
  18. package/docs/rules/no-if.md +4 -4
  19. package/docs/rules/no-interpolation-in-snapshots.md +6 -1
  20. package/docs/rules/no-jasmine-globals.md +10 -2
  21. package/docs/rules/no-large-snapshots.md +4 -2
  22. package/docs/rules/no-mocks-import.md +6 -1
  23. package/docs/rules/no-restricted-jest-methods.md +51 -0
  24. package/docs/rules/no-restricted-matchers.md +19 -4
  25. package/docs/rules/no-standalone-expect.md +6 -1
  26. package/docs/rules/no-test-prefixes.md +9 -1
  27. package/docs/rules/no-test-return-statement.md +2 -0
  28. package/docs/rules/prefer-called-with.md +2 -0
  29. package/docs/rules/prefer-comparison-matcher.md +5 -0
  30. package/docs/rules/prefer-each.md +56 -0
  31. package/docs/rules/prefer-equality-matcher.md +5 -0
  32. package/docs/rules/prefer-expect-assertions.md +5 -2
  33. package/docs/rules/prefer-expect-resolves.md +8 -1
  34. package/docs/rules/prefer-hooks-in-order.md +3 -1
  35. package/docs/rules/prefer-hooks-on-top.md +3 -1
  36. package/docs/rules/prefer-lowercase-title.md +5 -0
  37. package/docs/rules/prefer-mock-promise-shorthand.md +6 -1
  38. package/docs/rules/prefer-snapshot-hint.md +2 -0
  39. package/docs/rules/prefer-spy-on.md +5 -2
  40. package/docs/rules/prefer-strict-equal.md +5 -2
  41. package/docs/rules/prefer-to-be.md +8 -0
  42. package/docs/rules/prefer-to-contain.md +8 -2
  43. package/docs/rules/prefer-to-have-length.md +8 -2
  44. package/docs/rules/prefer-todo.md +5 -2
  45. package/docs/rules/require-hook.md +2 -0
  46. package/docs/rules/require-to-throw-message.md +2 -2
  47. package/docs/rules/require-top-level-describe.md +5 -1
  48. package/docs/rules/unbound-method.md +7 -2
  49. package/docs/rules/valid-describe-callback.md +6 -1
  50. package/docs/rules/valid-expect-in-promise.md +6 -1
  51. package/docs/rules/valid-expect.md +5 -2
  52. package/docs/rules/valid-title.md +9 -1
  53. package/lib/index.js +14 -25
  54. package/lib/processors/snapshot-processor.js +3 -5
  55. package/lib/rules/consistent-test-it.js +1 -19
  56. package/lib/rules/expect-expect.js +1 -18
  57. package/lib/rules/max-expects.js +0 -16
  58. package/lib/rules/max-nested-describe.js +0 -13
  59. package/lib/rules/no-alias-methods.js +1 -10
  60. package/lib/rules/no-commented-out-tests.js +0 -10
  61. package/lib/rules/no-conditional-expect.js +2 -23
  62. package/lib/rules/no-conditional-in-test.js +0 -9
  63. package/lib/rules/no-deprecated-functions.js +2 -18
  64. package/lib/rules/no-disabled-tests.js +3 -19
  65. package/lib/rules/no-done-callback.js +20 -47
  66. package/lib/rules/no-duplicate-hooks.js +0 -12
  67. package/lib/rules/no-export.js +0 -12
  68. package/lib/rules/no-focused-tests.js +1 -17
  69. package/lib/rules/no-hooks.js +0 -7
  70. package/lib/rules/no-identical-title.js +0 -19
  71. package/lib/rules/no-if.js +0 -24
  72. package/lib/rules/no-interpolation-in-snapshots.js +0 -9
  73. package/lib/rules/no-jasmine-globals.js +1 -23
  74. package/lib/rules/no-large-snapshots.js +4 -24
  75. package/lib/rules/no-mocks-import.js +0 -12
  76. package/lib/rules/no-restricted-jest-methods.js +56 -0
  77. package/lib/rules/no-restricted-matchers.js +13 -28
  78. package/lib/rules/no-standalone-expect.js +7 -33
  79. package/lib/rules/no-test-prefixes.js +1 -13
  80. package/lib/rules/no-test-return-statement.js +0 -12
  81. package/lib/rules/prefer-called-with.js +0 -10
  82. package/lib/rules/prefer-comparison-matcher.js +8 -33
  83. package/lib/rules/prefer-each.js +80 -0
  84. package/lib/rules/prefer-equality-matcher.js +12 -25
  85. package/lib/rules/prefer-expect-assertions.js +14 -60
  86. package/lib/rules/prefer-expect-resolves.js +0 -12
  87. package/lib/rules/prefer-hooks-in-order.js +2 -16
  88. package/lib/rules/prefer-hooks-on-top.js +0 -9
  89. package/lib/rules/prefer-lowercase-title.js +0 -23
  90. package/lib/rules/prefer-mock-promise-shorthand.js +5 -26
  91. package/lib/rules/prefer-snapshot-hint.js +8 -34
  92. package/lib/rules/prefer-spy-on.js +0 -17
  93. package/lib/rules/prefer-strict-equal.js +1 -11
  94. package/lib/rules/prefer-to-be.js +12 -37
  95. package/lib/rules/prefer-to-contain.js +11 -21
  96. package/lib/rules/prefer-to-have-length.js +4 -16
  97. package/lib/rules/prefer-todo.js +2 -18
  98. package/lib/rules/require-hook.js +1 -25
  99. package/lib/rules/require-to-throw-message.js +0 -9
  100. package/lib/rules/require-top-level-describe.js +1 -18
  101. package/lib/rules/unbound-method.js +3 -30
  102. package/lib/rules/utils/accessors.js +6 -18
  103. package/lib/rules/utils/detectJestVersion.js +2 -7
  104. package/lib/rules/utils/followTypeAssertionChain.js +0 -4
  105. package/lib/rules/utils/index.js +0 -10
  106. package/lib/rules/utils/misc.js +14 -47
  107. package/lib/rules/utils/parseJestFnCall.js +51 -154
  108. package/lib/rules/valid-describe-callback.js +0 -17
  109. package/lib/rules/valid-expect-in-promise.js +28 -95
  110. package/lib/rules/valid-expect.js +5 -48
  111. package/lib/rules/valid-title.js +5 -40
  112. package/package.json +20 -16
  113. package/docs/rules/no-jest-import.md +0 -20
  114. 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 base rules list -->
199
-
200
- | Rule | Description | Configurations | Fixable |
201
- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------- | ---------------- | ------------ |
202
- | [consistent-test-it](docs/rules/consistent-test-it.md) | Have control over `test` and `it` usages | | ![fixable][] |
203
- | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | |
204
- | [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | |
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 | ![style][] | ![fixable][] |
207
- | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
208
- | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
209
- | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | |
210
- | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | ![recommended][] | ![fixable][] |
211
- | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended][] | |
212
- | [no-done-callback](docs/rules/no-done-callback.md) | Avoid using a callback in asynchronous tests and hooks | ![recommended][] | ![suggest][] |
213
- | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | |
214
- | [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests | ![recommended][] | |
215
- | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![suggest][] |
216
- | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
217
- | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
218
- | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | |
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
- | [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
222
- | [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ![recommended][] | |
223
- | [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | |
224
- | [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks | ![recommended][] | |
225
- | [no-test-prefixes](docs/rules/no-test-prefixes.md) | Use `.only` and `.skip` over `f` and `x` | ![recommended][] | ![fixable][] |
226
- | [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | |
227
- | [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | |
228
- | [prefer-comparison-matcher](docs/rules/prefer-comparison-matcher.md) | Suggest using the built-in comparison matchers | | ![fixable][] |
229
- | [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | ![suggest][] |
230
- | [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | ![suggest][] |
231
- | [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | Prefer `await expect(...).resolves` over `expect(await ...)` syntax | | ![fixable][] |
232
- | [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | |
233
- | [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | |
234
- | [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | ![fixable][] |
235
- | [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | Prefer mock resolved/rejected shorthands for promises | | ![fixable][] |
236
- | [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | Prefer including a hint with external snapshots | | |
237
- | [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | ![fixable][] |
238
- | [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | ![suggest][] |
239
- | [prefer-to-be](docs/rules/prefer-to-be.md) | Suggest using `toBe()` for primitive literals | ![style][] | ![fixable][] |
240
- | [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | ![style][] | ![fixable][] |
241
- | [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | ![style][] | ![fixable][] |
242
- | [prefer-todo](docs/rules/prefer-todo.md) | Suggest using `test.todo` | | ![fixable][] |
243
- | [require-hook](docs/rules/require-hook.md) | Require setup and teardown code to be within a hook | | |
244
- | [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | |
245
- | [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | |
246
- | [valid-describe-callback](docs/rules/valid-describe-callback.md) | Enforce valid `describe()` callback | ![recommended][] | |
247
- | [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ![recommended][] | |
248
- | [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Ensure promises that have expectations in their chain are valid | ![recommended][] | |
249
- | [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ![recommended][] | ![fixable][] |
250
-
251
- <!-- end base rules list -->
252
-
253
- ## TypeScript Rules
254
-
255
- In addition to the above rules, this plugin also includes a few advanced rules
256
- that are powered by type-checking information provided by TypeScript.
257
-
258
- In order to use these rules, you must be using `@typescript-eslint/parser` &
259
- adjust your eslint config as outlined
260
- [here](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md)
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
- # Have control over `test` and `it` usages (`consistent-test-it`)
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
- ## Rule Details
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 Details
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 Details
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 Details
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
- # Prevent calling `expect` conditionally (`no-conditional-expect`)
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 Details
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 Details
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, and is scheduled for
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, and is scheduled for
29
- removal in Jest 27.
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, and is scheduled
45
- for removal in Jest 27.
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 a future version of Jest.
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 Details
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
- # Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)
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 Details
7
+ ## Rule details
6
8
 
7
9
  Examples of **incorrect** code for this rule
8
10
 
@@ -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 Details
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 Details
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
@@ -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 Details
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 Details
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
@@ -1,10 +1,10 @@
1
1
  # Disallow conditional logic (`no-if`)
2
2
 
3
- ## Deprecated
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 Details
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 Details
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
- ### Rule details
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
- ### Default configuration
23
+ ## Examples
16
24
 
17
25
  The following patterns are considered warnings:
18
26