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
@@ -1,4 +1,6 @@
1
- # disallow large snapshots (`no-large-snapshots`)
1
+ # Disallow large snapshots (`no-large-snapshots`)
2
+
3
+ <!-- end auto-generated rule header -->
2
4
 
3
5
  When using Jest's snapshot capability one should be mindful of the size of
4
6
  created snapshots. As a general best practice snapshots should be limited in
@@ -22,7 +24,7 @@ module.exports = {
22
24
  };
23
25
  ```
24
26
 
25
- ## Rule Details
27
+ ## Rule details
26
28
 
27
29
  This rule looks at all Jest inline and external snapshots (files with `.snap`
28
30
  extension) and validates that each stored snapshot within those files does not
@@ -1,5 +1,10 @@
1
1
  # Disallow manually importing from `__mocks__` (`no-mocks-import`)
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
  When using `jest.mock`, your tests (just like the code being tested) should
4
9
  import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
5
10
  confusion, because you will have multiple instances of the mocked module:
@@ -14,7 +19,7 @@ test('x', () => {
14
19
  });
15
20
  ```
16
21
 
17
- ### Rule details
22
+ ## Rule details
18
23
 
19
24
  This rule reports imports from a path containing a `__mocks__` component.
20
25
 
@@ -0,0 +1,51 @@
1
+ # Disallow specific `jest.` methods (`no-restricted-jest-methods`)
2
+
3
+ <!-- end auto-generated rule header -->
4
+
5
+ You may wish to restrict the use of specific `jest` methods.
6
+
7
+ ## Rule details
8
+
9
+ This rule checks for the usage of specific methods on the `jest` object, which
10
+ can be used to disallow certain patterns such as spies and mocks.
11
+
12
+ ## Options
13
+
14
+ Restrictions are expressed in the form of a map, with the value being either a
15
+ string message to be shown, or `null` if a generic default message should be
16
+ used.
17
+
18
+ By default, this map is empty, meaning no `jest` methods are banned.
19
+
20
+ For example:
21
+
22
+ ```json
23
+ {
24
+ "jest/no-restricted-jest-methods": [
25
+ "error",
26
+ {
27
+ "advanceTimersByTime": null,
28
+ "spyOn": "Don't use spies"
29
+ }
30
+ ]
31
+ }
32
+ ```
33
+
34
+ Examples of **incorrect** code for this rule with the above configuration
35
+
36
+ ```js
37
+ jest.useFakeTimers();
38
+ it('calls the callback after 1 second via advanceTimersByTime', () => {
39
+ // ...
40
+
41
+ jest.advanceTimersByTime(1000);
42
+
43
+ // ...
44
+ });
45
+
46
+ test('plays video', () => {
47
+ const spy = jest.spyOn(video, 'play');
48
+
49
+ // ...
50
+ });
51
+ ```
@@ -1,15 +1,22 @@
1
1
  # Disallow specific matchers & modifiers (`no-restricted-matchers`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
5
+ You may want to ban specific matchers & modifiers from being used.
6
+
7
+ ## Rule details
8
+
3
9
  This rule bans specific matchers & modifiers from being used, and can suggest
4
10
  alternatives.
5
11
 
6
- ## Rule Details
12
+ ## Options
7
13
 
8
14
  Bans are expressed in the form of a map, with the value being either a string
9
15
  message to be shown, or `null` if the default rule message should be used.
10
16
 
11
- Both matchers, modifiers, and chains of the two are checked, allowing for
12
- specific variations of a matcher to be banned if desired.
17
+ Bans are checked against the start of the `expect` chain - this means that to
18
+ ban a specific matcher entirely you must specify all six permutations, but
19
+ allows you to ban modifiers as well.
13
20
 
14
21
  By default, this map is empty, meaning no matchers or modifiers are banned.
15
22
 
@@ -22,7 +29,12 @@ For example:
22
29
  {
23
30
  "toBeFalsy": null,
24
31
  "resolves": "Use `expect(await promise)` instead.",
25
- "not.toHaveBeenCalledWith": null
32
+ "toHaveBeenCalledWith": null,
33
+ "not.toHaveBeenCalledWith": null,
34
+ "resolves.toHaveBeenCalledWith": null,
35
+ "rejects.toHaveBeenCalledWith": null,
36
+ "resolves.not.toHaveBeenCalledWith": null,
37
+ "rejects.not.toHaveBeenCalledWith": null
26
38
  }
27
39
  ]
28
40
  }
@@ -32,15 +44,18 @@ Examples of **incorrect** code for this rule with the above configuration
32
44
 
33
45
  ```js
34
46
  it('is false', () => {
47
+ // if this has a modifer (i.e. `not.toBeFalsy`), it would be considered fine
35
48
  expect(a).toBeFalsy();
36
49
  });
37
50
 
38
51
  it('resolves', async () => {
52
+ // all uses of this modifier are disallowed, regardless of matcher
39
53
  await expect(myPromise()).resolves.toBe(true);
40
54
  });
41
55
 
42
56
  describe('when an error happens', () => {
43
57
  it('does not upload the file', async () => {
58
+ // all uses of this matcher are disallowed
44
59
  expect(uploadFileMock).not.toHaveBeenCalledWith('file.name');
45
60
  });
46
61
  });
@@ -1,10 +1,15 @@
1
1
  # Disallow using `expect` outside of `it` or `test` blocks (`no-standalone-expect`)
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 `expect` statements outside of a `test` or `it` block. An `expect`
4
9
  within a helper function (but outside of a `test` or `it` block) will not
5
10
  trigger this rule.
6
11
 
7
- ## Rule Details
12
+ ## Rule details
8
13
 
9
14
  This rule aims to eliminate `expect` statements that will not be executed. An
10
15
  `expect` inside of a `describe` block but outside of a `test` or `it` block or
@@ -1,4 +1,12 @@
1
- # Use `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)
1
+ # Require using `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)
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 -->
2
10
 
3
11
  Jest allows you to choose how you want to define focused and skipped tests, with
4
12
  multiple permutations for each:
@@ -1,5 +1,7 @@
1
1
  # Disallow explicitly returning from tests (`no-test-return-statement`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  Tests in Jest should be void and not return values.
4
6
 
5
7
  If you are returning Promises then you should update the test to use
@@ -1,5 +1,7 @@
1
1
  # Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  The `toBeCalled()` matcher is used to assert that a mock function has been
4
6
  called one or more times, without checking the arguments passed. The assertion
5
7
  is stronger when arguments are also validated using the `toBeCalledWith()`
@@ -1,5 +1,10 @@
1
1
  # Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
2
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 -->
7
+
3
8
  Jest has a number of built-in matchers for comparing numbers, which allow for
4
9
  more readable tests and error messages if an expectation fails.
5
10
 
@@ -0,0 +1,56 @@
1
+ # Prefer using `.each` rather than manual loops (`prefer-each`)
2
+
3
+ <!-- end auto-generated rule header -->
4
+
5
+ Reports where you might be able to use `.each` instead of native loops.
6
+
7
+ ## Rule details
8
+
9
+ This rule triggers a warning if you use test case functions like `describe`,
10
+ `test`, and `it`, in a native loop - generally you should be able to use `.each`
11
+ instead which gives better output and makes it easier to run specific cases.
12
+
13
+ Examples of **incorrect** code for this rule:
14
+
15
+ ```js
16
+ for (const number of getNumbers()) {
17
+ it('is greater than five', function () {
18
+ expect(number).toBeGreaterThan(5);
19
+ });
20
+ }
21
+
22
+ for (const [input, expected] of data) {
23
+ beforeEach(() => setupSomething(input));
24
+
25
+ test(`results in ${expected}`, () => {
26
+ expect(doSomething()).toBe(expected);
27
+ });
28
+ }
29
+ ```
30
+
31
+ Examples of **correct** code for this rule:
32
+
33
+ ```js
34
+ it.each(getNumbers())(
35
+ 'only returns numbers that are greater than seven',
36
+ number => {
37
+ expect(number).toBeGreaterThan(7);
38
+ },
39
+ );
40
+
41
+ describe.each(data)('when input is %s', ([input, expected]) => {
42
+ beforeEach(() => setupSomething(input));
43
+
44
+ test(`results in ${expected}`, () => {
45
+ expect(doSomething()).toBe(expected);
46
+ });
47
+ });
48
+
49
+ // we don't warn on loops _in_ test functions because those typically involve
50
+ // complex setup that is better done in the test function itself
51
+ it('returns numbers that are greater than five', () => {
52
+ for (const number of getNumbers()) {
53
+ expect(number).toBeGreaterThan(5);
54
+ }
55
+ });
56
+ ```
@@ -1,5 +1,10 @@
1
1
  # Suggest using the built-in equality matchers (`prefer-equality-matcher`)
2
2
 
3
+ 💡 This rule is manually fixable by
4
+ [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
5
+
6
+ <!-- end auto-generated rule header -->
7
+
3
8
  Jest has built-in matchers for expecting equality, which allow for more readable
4
9
  tests and error messages if an expectation fails.
5
10
 
@@ -1,5 +1,10 @@
1
1
  # Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)
2
2
 
3
+ 💡 This rule is manually fixable by
4
+ [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
5
+
6
+ <!-- end auto-generated rule header -->
7
+
3
8
  Ensure every test to have either `expect.assertions(<number of assertions>)` OR
4
9
  `expect.hasAssertions()` as its first expression.
5
10
 
@@ -27,8 +32,6 @@ test('my test', () => {
27
32
  });
28
33
  ```
29
34
 
30
- ### Default configuration
31
-
32
35
  The following patterns are considered warnings:
33
36
 
34
37
  ```js
@@ -1,5 +1,10 @@
1
1
  # Prefer `await expect(...).resolves` over `expect(await ...)` syntax (`prefer-expect-resolves`)
2
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 -->
7
+
3
8
  When working with promises, there are two primary ways you can test the resolved
4
9
  value:
5
10
 
@@ -48,6 +53,8 @@ it('is true', async () => {
48
53
  });
49
54
 
50
55
  it('errors', async () => {
51
- await expect(Promise.rejects('oh noes!')).rejects.toThrow('oh noes!');
56
+ await expect(Promise.reject(new Error('oh noes!'))).rejects.toThrowError(
57
+ 'oh noes!',
58
+ );
52
59
  });
53
60
  ```
@@ -1,5 +1,7 @@
1
1
  # Prefer having hooks in a consistent order (`prefer-hooks-in-order`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  While hooks can be setup in any order, they're always called by `jest` in this
4
6
  specific order:
5
7
 
@@ -11,7 +13,7 @@ specific order:
11
13
  This rule aims to make that more obvious by enforcing grouped hooks be setup in
12
14
  that order within tests.
13
15
 
14
- ## Rule Details
16
+ ## Rule details
15
17
 
16
18
  Examples of **incorrect** code for this rule
17
19
 
@@ -1,12 +1,14 @@
1
1
  # Suggest having hooks before any test cases (`prefer-hooks-on-top`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  While hooks can be setup anywhere in a test file, they are always called in a
4
6
  specific order, which means it can be confusing if they're intermixed with test
5
7
  cases.
6
8
 
7
9
  This rule helps to ensure that hooks are always defined before test cases.
8
10
 
9
- ## Rule Details
11
+ ## Rule details
10
12
 
11
13
  Examples of **incorrect** code for this rule
12
14
 
@@ -1,5 +1,10 @@
1
1
  # Enforce lowercase test names (`prefer-lowercase-title`)
2
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 -->
7
+
3
8
  ## Rule details
4
9
 
5
10
  Enforce `it`, `test` and `describe` to have descriptions that begin with a
@@ -1,11 +1,16 @@
1
1
  # Prefer mock resolved/rejected shorthands for promises (`prefer-mock-promise-shorthand`)
2
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 -->
7
+
3
8
  When working with mocks of functions that return promises, Jest provides some
4
9
  API sugar functions to reduce the amount of boilerplate you have to write.
5
10
 
6
11
  These methods should be preferred when possible.
7
12
 
8
- ## Rule Details
13
+ ## Rule details
9
14
 
10
15
  The following patterns are warnings:
11
16
 
@@ -1,5 +1,7 @@
1
1
  # Prefer including a hint with external snapshots (`prefer-snapshot-hint`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  When working with external snapshot matchers it's considered best practice to
4
6
  provide a hint (as the last argument to the matcher) describing the expected
5
7
  snapshot content that will be included in the snapshots name by Jest.
@@ -1,5 +1,10 @@
1
1
  # Suggest using `jest.spyOn()` (`prefer-spy-on`)
2
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 -->
7
+
3
8
  When mocking a function by overwriting a property you have to manually restore
4
9
  the original implementation when cleaning up. When using `jest.spyOn()` Jest
5
10
  keeps track of changes, and they can be restored with `jest.restoreAllMocks()`,
@@ -24,8 +29,6 @@ jest.spyOn(Date, 'now').mockReturnValue(10); // Will always return 10
24
29
  This rule triggers a warning if an object's property is overwritten with a jest
25
30
  mock.
26
31
 
27
- ### Default configuration
28
-
29
32
  The following patterns are considered warnings:
30
33
 
31
34
  ```js
@@ -1,5 +1,10 @@
1
1
  # Suggest using `toStrictEqual()` (`prefer-strict-equal`)
2
2
 
3
+ 💡 This rule is manually fixable by
4
+ [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
5
+
6
+ <!-- end auto-generated rule header -->
7
+
3
8
  `toStrictEqual` not only checks that two objects contain the same data but also
4
9
  that they have the same structure. It is common to expect objects to not only
5
10
  have identical values but also to have identical keys. A stricter equality will
@@ -9,8 +14,6 @@ catch cases where two objects do not have identical keys.
9
14
 
10
15
  This rule triggers a warning if `toEqual()` is used to assert equality.
11
16
 
12
- ### Default configuration
13
-
14
17
  The following pattern is considered warning:
15
18
 
16
19
  ```js
@@ -1,5 +1,13 @@
1
1
  # Suggest using `toBe()` for primitive literals (`prefer-to-be`)
2
2
 
3
+ 💼 This rule is enabled in the 🎨 `style`
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
  When asserting against primitive literals such as numbers and strings, the
4
12
  equality matchers all operate the same, but read slightly differently in code.
5
13
 
@@ -1,5 +1,13 @@
1
1
  # Suggest using `toContain()` (`prefer-to-contain`)
2
2
 
3
+ 💼 This rule is enabled in the 🎨 `style`
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
  In order to have a better failure message, `toContain()` should be used upon
4
12
  asserting expectations on an array containing an object.
5
13
 
@@ -20,8 +28,6 @@ expect(a.includes(b)).not.toBe(true);
20
28
  expect(a.includes(b)).toBe(false);
21
29
  ```
22
30
 
23
- ### Default configuration
24
-
25
31
  The following patterns are considered warnings:
26
32
 
27
33
  ```js
@@ -1,5 +1,13 @@
1
1
  # Suggest using `toHaveLength()` (`prefer-to-have-length`)
2
2
 
3
+ 💼 This rule is enabled in the 🎨 `style`
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
  In order to have a better failure message, `toHaveLength()` should be used upon
4
12
  asserting expectations on objects length property.
5
13
 
@@ -14,8 +22,6 @@ expect(files.length).toBe(1);
14
22
 
15
23
  This rule is enabled by default.
16
24
 
17
- ### Default configuration
18
-
19
25
  The following patterns are considered warnings:
20
26
 
21
27
  ```js
@@ -1,5 +1,10 @@
1
1
  # Suggest using `test.todo` (`prefer-todo`)
2
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 -->
7
+
3
8
  When test cases are empty then it is better to mark them as `test.todo` as it
4
9
  will be highlighted in the summary output.
5
10
 
@@ -11,8 +16,6 @@ This rule triggers a warning if empty test cases are used without 'test.todo'.
11
16
  test('i need to write this test');
12
17
  ```
13
18
 
14
- ### Default configuration
15
-
16
19
  The following pattern is considered warning:
17
20
 
18
21
  ```js
@@ -1,5 +1,7 @@
1
1
  # Require setup and teardown code to be within a hook (`require-hook`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  Often while writing tests you have some setup work that needs to happen before
4
6
  tests run, and you have some finishing work that needs to happen after tests
5
7
  run. Jest provides helper functions to handle this.
@@ -1,5 +1,7 @@
1
1
  # Require a message for `toThrow()` (`require-to-throw-message`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  `toThrow()` (and its alias `toThrowError()`) is used to check if an error is
4
6
  thrown by a function call, such as in `expect(() => a()).toThrow()`. However, if
5
7
  no message is defined, then the test will pass for any thrown error. Requiring a
@@ -10,8 +12,6 @@ message ensures that the intended error is thrown.
10
12
  This rule triggers a warning if `toThrow()` or `toThrowError()` is used without
11
13
  an error message.
12
14
 
13
- ### Default configuration
14
-
15
15
  The following patterns are considered warnings:
16
16
 
17
17
  ```js
@@ -1,11 +1,13 @@
1
1
  # Require test cases and hooks to be inside a `describe` block (`require-top-level-describe`)
2
2
 
3
+ <!-- end auto-generated rule header -->
4
+
3
5
  Jest allows you to organise your test files the way you want it. However, the
4
6
  more your codebase grows, the more it becomes hard to navigate in your test
5
7
  files. This rule makes sure you provide at least a top-level `describe` block in
6
8
  your test file.
7
9
 
8
- ## Rule Details
10
+ ## Rule details
9
11
 
10
12
  This rule triggers a warning if a test case (`test` and `it`) or a hook
11
13
  (`beforeAll`, `beforeEach`, `afterEach`, `afterAll`) is not located in a
@@ -47,6 +49,8 @@ describe('test suite', () => {
47
49
  });
48
50
  ```
49
51
 
52
+ ## Options
53
+
50
54
  You can also enforce a limit on the number of describes allowed at the top-level
51
55
  using the `maxNumberOfTopLevelDescribes` option:
52
56
 
@@ -1,6 +1,10 @@
1
1
  # Enforce unbound methods are called with their expected scope (`unbound-method`)
2
2
 
3
- ## Rule Details
3
+ 💭 This rule requires type information.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ ## Rule details
4
8
 
5
9
  This rule extends the base [`@typescript-eslint/unbound-method`][original-rule]
6
10
  rule, meaning you must depend on `@typescript-eslint/eslint-plugin` for it to
@@ -46,7 +50,8 @@ which should be applied to the rest of your codebase.
46
50
 
47
51
  ## Options
48
52
 
49
- See [`@typescript-eslint/unbound-method`][original-rule] options.
53
+ See [`@typescript-eslint/unbound-method`][original-rule] options (e.g.
54
+ `ignoreStatic`).
50
55
 
51
56
  <sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>
52
57
 
@@ -1,9 +1,14 @@
1
1
  # Enforce valid `describe()` callback (`valid-describe-callback`)
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
  Using an improper `describe()` callback function can lead to unexpected test
4
9
  errors.
5
10
 
6
- ## Rule Details
11
+ ## Rule details
7
12
 
8
13
  This rule validates that the second parameter of a `describe()` function is a
9
14
  callback function. This callback function:
@@ -1,4 +1,9 @@
1
- # Ensure promises that have expectations in their chain are valid (`valid-expect-in-promise`)
1
+ # Require promises that have expectations in their chain to be valid (`valid-expect-in-promise`)
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
  Ensure promises that include expectations are returned or awaited.
4
9
 
@@ -1,5 +1,10 @@
1
1
  # Enforce valid `expect()` usage (`valid-expect`)
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
  Ensure `expect()` is called with a single argument and there is an actual
4
9
  expectation made.
5
10
 
@@ -103,8 +108,6 @@ This is useful when you're using libraries that increase the number of arguments
103
108
  supported by `expect`, such as
104
109
  [`jest-expect-message`](https://www.npmjs.com/package/jest-expect-message).
105
110
 
106
- ### Default configuration
107
-
108
111
  The following patterns are considered warnings:
109
112
 
110
113
  ```js
@@ -1,5 +1,13 @@
1
1
  # Enforce valid titles (`valid-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
+ 🔧 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
  Checks that the title of Jest blocks are valid by ensuring that titles are:
4
12
 
5
13
  - not empty,
@@ -7,7 +15,7 @@ Checks that the title of Jest blocks are valid by ensuring that titles are:
7
15
  - not prefixed with their block name,
8
16
  - have no leading or trailing spaces
9
17
 
10
- ## Rule Details
18
+ ## Rule details
11
19
 
12
20
  **emptyTitle**
13
21