eslint-plugin-jest 27.1.3 → 27.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -80
- package/docs/rules/consistent-test-it.md +4 -11
- package/docs/rules/expect-expect.md +3 -4
- package/docs/rules/max-expects.md +1 -5
- package/docs/rules/max-nested-describe.md +1 -5
- package/docs/rules/no-alias-methods.md +8 -10
- package/docs/rules/no-commented-out-tests.md +3 -4
- package/docs/rules/no-conditional-expect.md +4 -5
- package/docs/rules/no-conditional-in-test.md +1 -5
- package/docs/rules/no-deprecated-functions.md +5 -7
- package/docs/rules/no-disabled-tests.md +3 -4
- package/docs/rules/no-done-callback.md +6 -8
- package/docs/rules/no-duplicate-hooks.md +1 -5
- package/docs/rules/no-export.md +3 -4
- package/docs/rules/no-focused-tests.md +5 -7
- package/docs/rules/no-hooks.md +1 -5
- package/docs/rules/no-identical-title.md +3 -4
- package/docs/rules/no-if.md +2 -2
- package/docs/rules/no-interpolation-in-snapshots.md +3 -4
- package/docs/rules/no-jasmine-globals.md +6 -8
- package/docs/rules/no-large-snapshots.md +2 -6
- package/docs/rules/no-mocks-import.md +3 -4
- package/docs/rules/no-restricted-jest-methods.md +1 -5
- package/docs/rules/no-restricted-matchers.md +1 -5
- package/docs/rules/no-standalone-expect.md +3 -4
- package/docs/rules/no-test-prefixes.md +6 -8
- package/docs/rules/no-test-return-statement.md +1 -5
- package/docs/rules/prefer-called-with.md +1 -5
- package/docs/rules/prefer-comparison-matcher.md +3 -8
- package/docs/rules/prefer-each.md +1 -5
- package/docs/rules/prefer-equality-matcher.md +3 -8
- package/docs/rules/prefer-expect-assertions.md +3 -10
- package/docs/rules/prefer-expect-resolves.md +3 -8
- package/docs/rules/prefer-hooks-in-order.md +1 -5
- package/docs/rules/prefer-hooks-on-top.md +1 -5
- package/docs/rules/prefer-lowercase-title.md +3 -8
- package/docs/rules/prefer-mock-promise-shorthand.md +3 -8
- package/docs/rules/prefer-snapshot-hint.md +1 -5
- package/docs/rules/prefer-spy-on.md +3 -10
- package/docs/rules/prefer-strict-equal.md +3 -10
- package/docs/rules/prefer-to-be.md +5 -7
- package/docs/rules/prefer-to-contain.md +5 -9
- package/docs/rules/prefer-to-have-length.md +5 -9
- package/docs/rules/prefer-todo.md +3 -10
- package/docs/rules/require-hook.md +1 -5
- package/docs/rules/require-to-throw-message.md +1 -7
- package/docs/rules/require-top-level-describe.md +1 -5
- package/docs/rules/unbound-method.md +2 -4
- package/docs/rules/valid-describe-callback.md +3 -4
- package/docs/rules/valid-expect-in-promise.md +4 -5
- package/docs/rules/valid-expect.md +3 -6
- package/docs/rules/valid-title.md +5 -7
- package/lib/rules/consistent-test-it.js +1 -1
- package/lib/rules/no-conditional-expect.js +1 -1
- package/lib/rules/no-disabled-tests.js +1 -1
- package/lib/rules/no-done-callback.js +1 -1
- package/lib/rules/no-jasmine-globals.js +1 -1
- package/lib/rules/no-large-snapshots.js +1 -1
- package/lib/rules/no-test-prefixes.js +1 -1
- package/lib/rules/utils/parseJestFnCall.js +17 -43
- package/lib/rules/valid-expect-in-promise.js +1 -1
- package/lib/rules/valid-title.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -195,70 +195,84 @@ 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
|
-
| [no-
|
|
228
|
-
| [
|
|
229
|
-
| [
|
|
230
|
-
| [
|
|
231
|
-
| [
|
|
232
|
-
| [
|
|
233
|
-
| [
|
|
234
|
-
| [
|
|
235
|
-
| [
|
|
236
|
-
| [
|
|
237
|
-
| [
|
|
238
|
-
| [
|
|
239
|
-
| [
|
|
240
|
-
| [
|
|
241
|
-
| [prefer-
|
|
242
|
-
| [prefer-
|
|
243
|
-
| [prefer-
|
|
244
|
-
| [prefer-
|
|
245
|
-
| [
|
|
246
|
-
| [
|
|
247
|
-
| [
|
|
248
|
-
| [
|
|
249
|
-
| [
|
|
250
|
-
| [
|
|
251
|
-
| [
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
|
262
276
|
[here](https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TYPED_LINTING.md).
|
|
263
277
|
|
|
264
278
|
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
@@ -269,14 +283,6 @@ used on JavaScript and TypeScript projects.
|
|
|
269
283
|
Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
|
|
270
284
|
as it extends the original `unbound-method` rule from that plugin.
|
|
271
285
|
|
|
272
|
-
<!-- begin type rules list -->
|
|
273
|
-
|
|
274
|
-
| Rule | Description | Configurations | Fixable |
|
|
275
|
-
| ---------------------------------------------- | ------------------------------------------------------------ | -------------- | ------- |
|
|
276
|
-
| [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | |
|
|
277
|
-
|
|
278
|
-
<!-- end type rules list -->
|
|
279
|
-
|
|
280
286
|
## Credit
|
|
281
287
|
|
|
282
288
|
- [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha)
|
|
@@ -290,25 +296,20 @@ This is a sister plugin to `eslint-plugin-jest` that provides support for the
|
|
|
290
296
|
matchers provided by
|
|
291
297
|
[`jest-extended`](https://github.com/jest-community/jest-extended).
|
|
292
298
|
|
|
293
|
-
https://github.com/jest-community/eslint-plugin-jest-extended
|
|
299
|
+
<https://github.com/jest-community/eslint-plugin-jest-extended>
|
|
294
300
|
|
|
295
301
|
### eslint-plugin-jest-formatting
|
|
296
302
|
|
|
297
303
|
This project aims to provide formatting rules (auto-fixable where possible) to
|
|
298
304
|
ensure consistency and readability in jest test suites.
|
|
299
305
|
|
|
300
|
-
https://github.com/dangreenisrael/eslint-plugin-jest-formatting
|
|
306
|
+
<https://github.com/dangreenisrael/eslint-plugin-jest-formatting>
|
|
301
307
|
|
|
302
308
|
### eslint-plugin-istanbul
|
|
303
309
|
|
|
304
310
|
A set of rules to enforce good practices for Istanbul, one of the code coverage
|
|
305
311
|
tools used by Jest.
|
|
306
312
|
|
|
307
|
-
https://github.com/istanbuljs/eslint-plugin-istanbul
|
|
313
|
+
<https://github.com/istanbuljs/eslint-plugin-istanbul>
|
|
308
314
|
|
|
309
|
-
[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
|
|
310
|
-
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
|
|
311
|
-
[fixable]: https://img.shields.io/badge/-fixable-green.svg
|
|
312
|
-
[style]: https://img.shields.io/badge/-style-blue.svg
|
|
313
|
-
[deprecated]: https://img.shields.io/badge/-deprecated-red.svg
|
|
314
315
|
[`no-deprecated-functions`]: docs/rules/no-deprecated-functions.md
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Enforce `test` and `it` usage conventions (`consistent-test-it`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
🔧 This rule is automatically fixable by the
|
|
4
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
|
|
9
|
-
on the command line.
|
|
10
|
-
|
|
11
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
12
7
|
|
|
13
8
|
Jest allows you to choose how you want to define your tests, using the `it` or
|
|
14
9
|
the `test` keywords, with multiple permutations for each:
|
|
@@ -81,8 +76,6 @@ describe('foo', function () {
|
|
|
81
76
|
});
|
|
82
77
|
```
|
|
83
78
|
|
|
84
|
-
### Default configuration
|
|
85
|
-
|
|
86
79
|
The default configuration forces all top-level tests to use `test` and all tests
|
|
87
80
|
nested within `describe` to use `it`.
|
|
88
81
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Enforce assertion to be made in a test body (`expect-expect`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
⚠️ This rule _warns_ in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Ensure that there is at least one `expect` call made in a test.
|
|
10
9
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Enforces a maximum number assertion calls in a test body (`max-expects`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
As more assertions are made, there is a possible tendency for the test to be
|
|
10
6
|
more likely to mix multiple objectives. To avoid this, this rule reports when
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
While it's useful to be able to group your tests together within the same file
|
|
10
6
|
using `describe()`, having too many levels of nesting throughout your tests make
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# Disallow alias methods (`no-alias-methods`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
|
|
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).
|
|
6
7
|
|
|
7
|
-
🔧 This rule is automatically fixable
|
|
8
|
-
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
|
|
9
|
-
on the command line.
|
|
8
|
+
🔧 This rule is automatically fixable by the
|
|
9
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
10
10
|
|
|
11
|
-
<!-- end rule header -->
|
|
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/facebook/jest/issues/13164 for more
|
|
14
|
+
> <https://github.com/facebook/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
|
|
@@ -24,8 +24,6 @@ method names used.
|
|
|
24
24
|
This rule triggers a warning if the alias name, rather than the canonical name,
|
|
25
25
|
of a method is used.
|
|
26
26
|
|
|
27
|
-
### Default configuration
|
|
28
|
-
|
|
29
27
|
The following patterns are considered warnings:
|
|
30
28
|
|
|
31
29
|
```js
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow commented out tests (`no-commented-out-tests`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
⚠️ This rule _warns_ in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
This rule raises a warning about commented out tests. It's similar to
|
|
10
9
|
no-disabled-tests rule.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow calling `expect` conditionally (`no-conditional-expect`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
This rule prevents the use of `expect` in conditional blocks, such as `if`s &
|
|
10
9
|
`catch`s.
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow conditional logic in tests (`no-conditional-in-test`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
Conditional logic in tests is usually an indication that a test is attempting to
|
|
10
6
|
cover too much, and not testing the logic it intends to. Each branch of code
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Disallow use of deprecated functions (`no-deprecated-functions`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
🔧 This rule is automatically fixable
|
|
8
|
-
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
|
|
9
|
-
on the command line.
|
|
6
|
+
🔧 This rule is automatically fixable by the
|
|
7
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
10
8
|
|
|
11
|
-
<!-- end rule header -->
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
12
10
|
|
|
13
11
|
Over the years Jest has accrued some debt in the form of functions that have
|
|
14
12
|
either been renamed for clarity, or replaced with more powerful APIs.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow disabled tests (`no-disabled-tests`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
⚠️ This rule _warns_ in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Jest has a feature that allows you to temporarily mark tests as disabled. This
|
|
10
9
|
feature is often helpful while debugging or to create placeholders for future
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using a callback in asynchronous tests and hooks (`no-done-callback`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
💡 This rule
|
|
8
|
-
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
|
9
|
-
that can be applied manually.
|
|
6
|
+
💡 This rule is manually fixable by
|
|
7
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
10
8
|
|
|
11
|
-
<!-- end rule header -->
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
12
10
|
|
|
13
11
|
When calling asynchronous code in hooks and tests, `jest` needs to know when the
|
|
14
12
|
asynchronous work is complete to progress the current run.
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
A `describe` block should not contain duplicate hooks.
|
|
10
6
|
|
package/docs/rules/no-export.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow using `exports` in files containing tests (`no-export`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Prevents using `exports` if a file has one or more tests in it.
|
|
10
9
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Disallow focused tests (`no-focused-tests`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
💡 This rule
|
|
8
|
-
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
|
9
|
-
that can be applied manually.
|
|
6
|
+
💡 This rule is manually fixable by
|
|
7
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
10
8
|
|
|
11
|
-
<!-- end rule header -->
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
12
10
|
|
|
13
11
|
<!-- prettier-ignore -->
|
|
14
12
|
Jest has a feature that allows you to focus tests by appending `.only` or
|
package/docs/rules/no-hooks.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow setup and teardown hooks (`no-hooks`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
Jest provides global functions for setup and teardown tasks, which are called
|
|
10
6
|
before/after each test case and each test suite. The use of these hooks promotes
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow identical titles (`no-identical-title`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Having identical titles for two different tests or test suites may create
|
|
10
9
|
confusion. For example, when a test with the same title as another test in the
|
package/docs/rules/no-if.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Disallow conditional logic (`no-if`)
|
|
2
2
|
|
|
3
3
|
❌ This rule is deprecated. It was replaced by
|
|
4
|
-
[no-conditional-in-test](no-conditional-in-test.md).
|
|
4
|
+
[`no-conditional-in-test`](no-conditional-in-test.md).
|
|
5
5
|
|
|
6
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
7
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
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Prevents the use of string interpolations in snapshots.
|
|
10
9
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Disallow Jasmine globals (`no-jasmine-globals`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
🔧 This rule is automatically fixable
|
|
8
|
-
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
|
|
9
|
-
on the command line.
|
|
6
|
+
🔧 This rule is automatically fixable by the
|
|
7
|
+
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
10
8
|
|
|
11
|
-
<!-- end rule header -->
|
|
9
|
+
<!-- end auto-generated rule header -->
|
|
12
10
|
|
|
13
11
|
`jest` uses `jasmine` as a test runner. A side effect of this is that both a
|
|
14
12
|
`jasmine` object, and some jasmine-specific globals, are exposed to the test
|
|
@@ -22,7 +20,7 @@ API.
|
|
|
22
20
|
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
|
|
23
21
|
and suggests alternatives from Jest's own API.
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
## Examples
|
|
26
24
|
|
|
27
25
|
The following patterns are considered warnings:
|
|
28
26
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow large snapshots (`no-large-snapshots`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
6
|
-
|
|
7
|
-
<!-- end rule header -->
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
8
4
|
|
|
9
5
|
When using Jest's snapshot capability one should be mindful of the size of
|
|
10
6
|
created snapshots. As a general best practice snapshots should be limited in
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow manually importing from `__mocks__` (`no-mocks-import`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `recommended`.
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended`
|
|
4
|
+
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
|
|
6
5
|
|
|
7
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
When using `jest.mock`, your tests (just like the code being tested) should
|
|
10
9
|
import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
|