eslint-plugin-jest 27.1.3 → 27.1.4
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-done-callback.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 +27 -8
- package/lib/rules/valid-expect-in-promise.js +1 -1
- package/package.json +3 -2
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow specific `jest.` methods (`no-restricted-jest-methods`)
|
|
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
|
You may wish to restrict the use of specific `jest` methods.
|
|
10
6
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow specific matchers & modifiers (`no-restricted-matchers`)
|
|
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
|
You may want to ban specific matchers & modifiers from being used.
|
|
10
6
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Disallow using `expect` outside of `it` or `test` blocks (`no-standalone-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
|
Prevents `expect` statements outside of a `test` or `it` block. An `expect`
|
|
10
9
|
within a helper function (but outside of a `test` or `it` block) will not
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Require using `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)
|
|
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 allows you to choose how you want to define focused and skipped tests, with
|
|
14
12
|
multiple permutations for each:
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Disallow explicitly returning from tests (`no-test-return-statement`)
|
|
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
|
Tests in Jest should be void and not return values.
|
|
10
6
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)
|
|
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
|
The `toBeCalled()` matcher is used to assert that a mock function has been
|
|
10
6
|
called one or more times, without checking the arguments passed. The assertion
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
|
|
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 has a number of built-in matchers for comparing numbers, which allow for
|
|
14
9
|
more readable tests and error messages if an expectation fails.
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Prefer using `.each` rather than manual loops (`prefer-each`)
|
|
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
|
Reports where you might be able to use `.each` instead of native loops.
|
|
10
6
|
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
💡 This rule is manually fixable by
|
|
4
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
|
9
|
-
that can be applied manually.
|
|
10
|
-
|
|
11
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
12
7
|
|
|
13
8
|
Jest has built-in matchers for expecting equality, which allow for more readable
|
|
14
9
|
tests and error messages if an expectation fails.
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
💡 This rule is manually fixable by
|
|
4
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
|
9
|
-
that can be applied manually.
|
|
10
|
-
|
|
11
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
12
7
|
|
|
13
8
|
Ensure every test to have either `expect.assertions(<number of assertions>)` OR
|
|
14
9
|
`expect.hasAssertions()` as its first expression.
|
|
@@ -37,8 +32,6 @@ test('my test', () => {
|
|
|
37
32
|
});
|
|
38
33
|
```
|
|
39
34
|
|
|
40
|
-
### Default configuration
|
|
41
|
-
|
|
42
35
|
The following patterns are considered warnings:
|
|
43
36
|
|
|
44
37
|
```js
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Prefer `await expect(...).resolves` over `expect(await ...)` syntax (`prefer-expect-resolves`)
|
|
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
|
When working with promises, there are two primary ways you can test the resolved
|
|
14
9
|
value:
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Prefer having hooks in a consistent order (`prefer-hooks-in-order`)
|
|
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 hooks can be setup in any order, they're always called by `jest` in this
|
|
10
6
|
specific order:
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Suggest having hooks before any test cases (`prefer-hooks-on-top`)
|
|
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 hooks can be setup anywhere in a test file, they are always called in a
|
|
10
6
|
specific order, which means it can be confusing if they're intermixed with test
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Enforce lowercase test names (`prefer-lowercase-title`)
|
|
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
|
## Rule details
|
|
14
9
|
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Prefer mock resolved/rejected shorthands for promises (`prefer-mock-promise-shorthand`)
|
|
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
|
When working with mocks of functions that return promises, Jest provides some
|
|
14
9
|
API sugar functions to reduce the amount of boilerplate you have to write.
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Prefer including a hint with external snapshots (`prefer-snapshot-hint`)
|
|
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 working with external snapshot matchers it's considered best practice to
|
|
10
6
|
provide a hint (as the last argument to the matcher) describing the expected
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using `jest.spyOn()` (`prefer-spy-on`)
|
|
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
|
When mocking a function by overwriting a property you have to manually restore
|
|
14
9
|
the original implementation when cleaning up. When using `jest.spyOn()` Jest
|
|
@@ -34,8 +29,6 @@ jest.spyOn(Date, 'now').mockReturnValue(10); // Will always return 10
|
|
|
34
29
|
This rule triggers a warning if an object's property is overwritten with a jest
|
|
35
30
|
mock.
|
|
36
31
|
|
|
37
|
-
### Default configuration
|
|
38
|
-
|
|
39
32
|
The following patterns are considered warnings:
|
|
40
33
|
|
|
41
34
|
```js
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using `toStrictEqual()` (`prefer-strict-equal`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
`all`.
|
|
3
|
+
💡 This rule is manually fixable by
|
|
4
|
+
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
|
9
|
-
that can be applied manually.
|
|
10
|
-
|
|
11
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
12
7
|
|
|
13
8
|
`toStrictEqual` not only checks that two objects contain the same data but also
|
|
14
9
|
that they have the same structure. It is common to expect objects to not only
|
|
@@ -19,8 +14,6 @@ catch cases where two objects do not have identical keys.
|
|
|
19
14
|
|
|
20
15
|
This rule triggers a warning if `toEqual()` is used to assert equality.
|
|
21
16
|
|
|
22
|
-
### Default configuration
|
|
23
|
-
|
|
24
17
|
The following pattern is considered warning:
|
|
25
18
|
|
|
26
19
|
```js
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Suggest using `toBe()` for primitive literals (`prefer-to-be`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `style`.
|
|
3
|
+
💼 This rule is enabled in the 🎨 `style`
|
|
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
|
When asserting against primitive literals such as numbers and strings, the
|
|
14
12
|
equality matchers all operate the same, but read slightly differently in code.
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Suggest using `toContain()` (`prefer-to-contain`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `style`.
|
|
3
|
+
💼 This rule is enabled in the 🎨 `style`
|
|
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
|
In order to have a better failure message, `toContain()` should be used upon
|
|
14
12
|
asserting expectations on an array containing an object.
|
|
@@ -30,8 +28,6 @@ expect(a.includes(b)).not.toBe(true);
|
|
|
30
28
|
expect(a.includes(b)).toBe(false);
|
|
31
29
|
```
|
|
32
30
|
|
|
33
|
-
### Default configuration
|
|
34
|
-
|
|
35
31
|
The following patterns are considered warnings:
|
|
36
32
|
|
|
37
33
|
```js
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Suggest using `toHaveLength()` (`prefer-to-have-length`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the
|
|
4
|
-
[
|
|
5
|
-
`all`, `style`.
|
|
3
|
+
💼 This rule is enabled in the 🎨 `style`
|
|
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
|
In order to have a better failure message, `toHaveLength()` should be used upon
|
|
14
12
|
asserting expectations on objects length property.
|
|
@@ -24,8 +22,6 @@ expect(files.length).toBe(1);
|
|
|
24
22
|
|
|
25
23
|
This rule is enabled by default.
|
|
26
24
|
|
|
27
|
-
### Default configuration
|
|
28
|
-
|
|
29
25
|
The following patterns are considered warnings:
|
|
30
26
|
|
|
31
27
|
```js
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# Suggest using `test.todo` (`prefer-todo`)
|
|
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
|
When test cases are empty then it is better to mark them as `test.todo` as it
|
|
14
9
|
will be highlighted in the summary output.
|
|
@@ -21,8 +16,6 @@ This rule triggers a warning if empty test cases are used without 'test.todo'.
|
|
|
21
16
|
test('i need to write this test');
|
|
22
17
|
```
|
|
23
18
|
|
|
24
|
-
### Default configuration
|
|
25
|
-
|
|
26
19
|
The following pattern is considered warning:
|
|
27
20
|
|
|
28
21
|
```js
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Require setup and teardown code to be within a hook (`require-hook`)
|
|
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
|
Often while writing tests you have some setup work that needs to happen before
|
|
10
6
|
tests run, and you have some finishing work that needs to happen after tests
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Require a message for `toThrow()` (`require-to-throw-message`)
|
|
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
|
`toThrow()` (and its alias `toThrowError()`) is used to check if an error is
|
|
10
6
|
thrown by a function call, such as in `expect(() => a()).toThrow()`. However, if
|
|
@@ -16,8 +12,6 @@ message ensures that the intended error is thrown.
|
|
|
16
12
|
This rule triggers a warning if `toThrow()` or `toThrowError()` is used without
|
|
17
13
|
an error message.
|
|
18
14
|
|
|
19
|
-
### Default configuration
|
|
20
|
-
|
|
21
15
|
The following patterns are considered warnings:
|
|
22
16
|
|
|
23
17
|
```js
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
# Require test cases and hooks to be inside a `describe` block (`require-top-level-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
|
Jest allows you to organise your test files the way you want it. However, the
|
|
10
6
|
more your codebase grows, the more it becomes hard to navigate in your test
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# Enforce unbound methods are called with their expected scope (`unbound-method`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
|
|
5
|
-
`all`.
|
|
3
|
+
💭 This rule requires type information.
|
|
6
4
|
|
|
7
|
-
<!-- end rule header -->
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
8
6
|
|
|
9
7
|
## Rule details
|
|
10
8
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Enforce valid `describe()` callback (`valid-describe-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
|
-
<!-- end rule header -->
|
|
6
|
+
<!-- end auto-generated rule header -->
|
|
8
7
|
|
|
9
8
|
Using an improper `describe()` callback function can lead to unexpected test
|
|
10
9
|
errors.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Require promises that have expectations in their chain to be valid (`valid-expect-in-promise`)
|
|
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
|
Ensure promises that include expectations are returned or awaited.
|
|
10
9
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Enforce valid `expect()` usage (`valid-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
|
Ensure `expect()` is called with a single argument and there is an actual
|
|
10
9
|
expectation made.
|
|
@@ -109,8 +108,6 @@ This is useful when you're using libraries that increase the number of arguments
|
|
|
109
108
|
supported by `expect`, such as
|
|
110
109
|
[`jest-expect-message`](https://www.npmjs.com/package/jest-expect-message).
|
|
111
110
|
|
|
112
|
-
### Default configuration
|
|
113
|
-
|
|
114
111
|
The following patterns are considered warnings:
|
|
115
112
|
|
|
116
113
|
```js
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# Enforce valid titles (`valid-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
|
-
🔧 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
|
Checks that the title of Jest blocks are valid by ensuring that titles are:
|
|
14
12
|
|
|
@@ -12,7 +12,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
12
12
|
meta: {
|
|
13
13
|
docs: {
|
|
14
14
|
category: 'Best Practices',
|
|
15
|
-
description: '
|
|
15
|
+
description: 'Enforce `test` and `it` usage conventions',
|
|
16
16
|
recommended: false
|
|
17
17
|
},
|
|
18
18
|
fixable: 'code',
|
|
@@ -11,7 +11,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
11
11
|
name: __filename,
|
|
12
12
|
meta: {
|
|
13
13
|
docs: {
|
|
14
|
-
description: '
|
|
14
|
+
description: 'Disallow calling `expect` conditionally',
|
|
15
15
|
category: 'Best Practices',
|
|
16
16
|
recommended: 'error'
|
|
17
17
|
},
|
|
@@ -24,7 +24,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
24
24
|
meta: {
|
|
25
25
|
docs: {
|
|
26
26
|
category: 'Best Practices',
|
|
27
|
-
description: '
|
|
27
|
+
description: 'Disallow using a callback in asynchronous tests and hooks',
|
|
28
28
|
recommended: 'error'
|
|
29
29
|
},
|
|
30
30
|
messages: {
|
|
@@ -11,7 +11,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
13
|
category: 'Best Practices',
|
|
14
|
-
description: '
|
|
14
|
+
description: 'Require using `.only` and `.skip` over `f` and `x`',
|
|
15
15
|
recommended: 'error'
|
|
16
16
|
},
|
|
17
17
|
messages: {
|