@depup/eslint-plugin-jest 29.15.1-depup.0

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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/changes.json +10 -0
  4. package/docs/rules/consistent-test-it.md +96 -0
  5. package/docs/rules/expect-expect.md +152 -0
  6. package/docs/rules/max-expects.md +78 -0
  7. package/docs/rules/max-nested-describe.md +134 -0
  8. package/docs/rules/no-alias-methods.md +57 -0
  9. package/docs/rules/no-commented-out-tests.md +68 -0
  10. package/docs/rules/no-conditional-expect.md +142 -0
  11. package/docs/rules/no-conditional-in-test.md +123 -0
  12. package/docs/rules/no-confusing-set-timeout.md +64 -0
  13. package/docs/rules/no-deprecated-functions.md +59 -0
  14. package/docs/rules/no-disabled-tests.md +72 -0
  15. package/docs/rules/no-done-callback.md +100 -0
  16. package/docs/rules/no-duplicate-hooks.md +79 -0
  17. package/docs/rules/no-error-equal.md +37 -0
  18. package/docs/rules/no-export.md +52 -0
  19. package/docs/rules/no-focused-tests.md +67 -0
  20. package/docs/rules/no-hooks.md +178 -0
  21. package/docs/rules/no-identical-title.md +59 -0
  22. package/docs/rules/no-interpolation-in-snapshots.md +67 -0
  23. package/docs/rules/no-jasmine-globals.md +69 -0
  24. package/docs/rules/no-large-snapshots.md +180 -0
  25. package/docs/rules/no-mocks-import.md +34 -0
  26. package/docs/rules/no-restricted-jest-methods.md +53 -0
  27. package/docs/rules/no-restricted-matchers.md +64 -0
  28. package/docs/rules/no-standalone-expect.md +106 -0
  29. package/docs/rules/no-test-prefixes.md +42 -0
  30. package/docs/rules/no-test-return-statement.md +50 -0
  31. package/docs/rules/no-unnecessary-assertion.md +41 -0
  32. package/docs/rules/no-unneeded-async-expect-function.md +41 -0
  33. package/docs/rules/no-untyped-mock-factory.md +74 -0
  34. package/docs/rules/padding-around-after-all-blocks.md +34 -0
  35. package/docs/rules/padding-around-after-each-blocks.md +38 -0
  36. package/docs/rules/padding-around-all.md +20 -0
  37. package/docs/rules/padding-around-before-all-blocks.md +37 -0
  38. package/docs/rules/padding-around-before-each-blocks.md +38 -0
  39. package/docs/rules/padding-around-describe-blocks.md +42 -0
  40. package/docs/rules/padding-around-expect-groups.md +44 -0
  41. package/docs/rules/padding-around-test-blocks.md +48 -0
  42. package/docs/rules/prefer-called-with.md +39 -0
  43. package/docs/rules/prefer-comparison-matcher.md +62 -0
  44. package/docs/rules/prefer-each.md +58 -0
  45. package/docs/rules/prefer-ending-with-an-expect.md +170 -0
  46. package/docs/rules/prefer-equality-matcher.md +36 -0
  47. package/docs/rules/prefer-expect-assertions.md +230 -0
  48. package/docs/rules/prefer-expect-resolves.md +62 -0
  49. package/docs/rules/prefer-hooks-in-order.md +137 -0
  50. package/docs/rules/prefer-hooks-on-top.md +124 -0
  51. package/docs/rules/prefer-importing-jest-globals.md +85 -0
  52. package/docs/rules/prefer-jest-mocked.md +40 -0
  53. package/docs/rules/prefer-lowercase-title.md +128 -0
  54. package/docs/rules/prefer-mock-promise-shorthand.md +41 -0
  55. package/docs/rules/prefer-mock-return-shorthand.md +50 -0
  56. package/docs/rules/prefer-snapshot-hint.md +192 -0
  57. package/docs/rules/prefer-spy-on.md +46 -0
  58. package/docs/rules/prefer-strict-equal.md +29 -0
  59. package/docs/rules/prefer-to-be.md +63 -0
  60. package/docs/rules/prefer-to-contain.md +53 -0
  61. package/docs/rules/prefer-to-have-been-called-times.md +43 -0
  62. package/docs/rules/prefer-to-have-been-called.md +35 -0
  63. package/docs/rules/prefer-to-have-length.md +41 -0
  64. package/docs/rules/prefer-todo.md +33 -0
  65. package/docs/rules/require-hook.md +187 -0
  66. package/docs/rules/require-to-throw-message.md +43 -0
  67. package/docs/rules/require-top-level-describe.md +86 -0
  68. package/docs/rules/unbound-method.md +61 -0
  69. package/docs/rules/valid-describe-callback.md +69 -0
  70. package/docs/rules/valid-expect-in-promise.md +79 -0
  71. package/docs/rules/valid-expect-with-promise.md +43 -0
  72. package/docs/rules/valid-expect.md +155 -0
  73. package/docs/rules/valid-mock-module-path.md +72 -0
  74. package/docs/rules/valid-title.md +319 -0
  75. package/index.d.ts +28 -0
  76. package/lib/globals.json +15 -0
  77. package/lib/index.js +85 -0
  78. package/lib/rules/consistent-test-it.js +101 -0
  79. package/lib/rules/expect-expect.js +102 -0
  80. package/lib/rules/max-expects.js +70 -0
  81. package/lib/rules/max-nested-describe.js +59 -0
  82. package/lib/rules/no-alias-methods.js +62 -0
  83. package/lib/rules/no-commented-out-tests.js +44 -0
  84. package/lib/rules/no-conditional-expect.js +80 -0
  85. package/lib/rules/no-conditional-in-test.js +63 -0
  86. package/lib/rules/no-confusing-set-timeout.js +61 -0
  87. package/lib/rules/no-deprecated-functions.js +81 -0
  88. package/lib/rules/no-disabled-tests.js +57 -0
  89. package/lib/rules/no-done-callback.js +120 -0
  90. package/lib/rules/no-duplicate-hooks.js +52 -0
  91. package/lib/rules/no-error-equal.js +41 -0
  92. package/lib/rules/no-export.js +61 -0
  93. package/lib/rules/no-focused-tests.js +63 -0
  94. package/lib/rules/no-hooks.js +51 -0
  95. package/lib/rules/no-identical-title.js +73 -0
  96. package/lib/rules/no-interpolation-in-snapshots.js +43 -0
  97. package/lib/rules/no-jasmine-globals.js +140 -0
  98. package/lib/rules/no-large-snapshots.js +100 -0
  99. package/lib/rules/no-mocks-import.js +46 -0
  100. package/lib/rules/no-restricted-jest-methods.js +53 -0
  101. package/lib/rules/no-restricted-matchers.js +60 -0
  102. package/lib/rules/no-standalone-expect.js +114 -0
  103. package/lib/rules/no-test-prefixes.js +48 -0
  104. package/lib/rules/no-test-return-statement.js +62 -0
  105. package/lib/rules/no-unnecessary-assertion.js +87 -0
  106. package/lib/rules/no-unneeded-async-expect-function.js +57 -0
  107. package/lib/rules/no-untyped-mock-factory.js +61 -0
  108. package/lib/rules/padding-around-after-all-blocks.js +17 -0
  109. package/lib/rules/padding-around-after-each-blocks.js +17 -0
  110. package/lib/rules/padding-around-all.js +15 -0
  111. package/lib/rules/padding-around-before-all-blocks.js +17 -0
  112. package/lib/rules/padding-around-before-each-blocks.js +17 -0
  113. package/lib/rules/padding-around-describe-blocks.js +17 -0
  114. package/lib/rules/padding-around-expect-groups.js +21 -0
  115. package/lib/rules/padding-around-test-blocks.js +17 -0
  116. package/lib/rules/prefer-called-with.js +47 -0
  117. package/lib/rules/prefer-comparison-matcher.js +111 -0
  118. package/lib/rules/prefer-each.js +77 -0
  119. package/lib/rules/prefer-ending-with-an-expect.js +102 -0
  120. package/lib/rules/prefer-equality-matcher.js +87 -0
  121. package/lib/rules/prefer-expect-assertions.js +237 -0
  122. package/lib/rules/prefer-expect-resolves.js +47 -0
  123. package/lib/rules/prefer-hooks-in-order.js +67 -0
  124. package/lib/rules/prefer-hooks-on-top.js +41 -0
  125. package/lib/rules/prefer-importing-jest-globals.js +126 -0
  126. package/lib/rules/prefer-jest-mocked.js +66 -0
  127. package/lib/rules/prefer-lowercase-title.js +128 -0
  128. package/lib/rules/prefer-mock-promise-shorthand.js +88 -0
  129. package/lib/rules/prefer-mock-return-shorthand.js +122 -0
  130. package/lib/rules/prefer-snapshot-hint.js +111 -0
  131. package/lib/rules/prefer-spy-on.js +80 -0
  132. package/lib/rules/prefer-strict-equal.js +46 -0
  133. package/lib/rules/prefer-to-be.js +98 -0
  134. package/lib/rules/prefer-to-contain.js +82 -0
  135. package/lib/rules/prefer-to-have-been-called-times.js +70 -0
  136. package/lib/rules/prefer-to-have-been-called.js +59 -0
  137. package/lib/rules/prefer-to-have-length.js +57 -0
  138. package/lib/rules/prefer-todo.js +72 -0
  139. package/lib/rules/require-hook.js +93 -0
  140. package/lib/rules/require-to-throw-message.js +45 -0
  141. package/lib/rules/require-top-level-describe.js +86 -0
  142. package/lib/rules/unbound-method.js +86 -0
  143. package/lib/rules/utils/accessors.js +127 -0
  144. package/lib/rules/utils/ast-utils.js +59 -0
  145. package/lib/rules/utils/detectJestVersion.js +24 -0
  146. package/lib/rules/utils/followTypeAssertionChain.js +10 -0
  147. package/lib/rules/utils/index.js +71 -0
  148. package/lib/rules/utils/misc.js +168 -0
  149. package/lib/rules/utils/padding.js +308 -0
  150. package/lib/rules/utils/parseJestFnCall.js +325 -0
  151. package/lib/rules/utils/ts.js +73 -0
  152. package/lib/rules/valid-describe-callback.js +94 -0
  153. package/lib/rules/valid-expect-in-promise.js +311 -0
  154. package/lib/rules/valid-expect-with-promise.js +54 -0
  155. package/lib/rules/valid-expect.js +302 -0
  156. package/lib/rules/valid-mock-module-path.js +90 -0
  157. package/lib/rules/valid-title.js +252 -0
  158. package/package.json +164 -0
@@ -0,0 +1,53 @@
1
+ # jest/no-restricted-jest-methods
2
+
3
+ 📝 Disallow specific `jest.` methods.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ You may wish to restrict the use of specific `jest` methods.
8
+
9
+ ## Rule details
10
+
11
+ This rule checks for the usage of specific methods on the `jest` object, which
12
+ can be used to disallow certain patterns such as spies and mocks.
13
+
14
+ ## Options
15
+
16
+ Restrictions are expressed in the form of a map, with the value being either a
17
+ string message to be shown, or `null` if a generic default message should be
18
+ used.
19
+
20
+ By default, this map is empty, meaning no `jest` methods are banned.
21
+
22
+ For example:
23
+
24
+ ```json
25
+ {
26
+ "jest/no-restricted-jest-methods": [
27
+ "error",
28
+ {
29
+ "advanceTimersByTime": null,
30
+ "spyOn": "Don't use spies"
31
+ }
32
+ ]
33
+ }
34
+ ```
35
+
36
+ Examples of **incorrect** code for this rule with the above configuration
37
+
38
+ ```js
39
+ jest.useFakeTimers();
40
+ it('calls the callback after 1 second via advanceTimersByTime', () => {
41
+ // ...
42
+
43
+ jest.advanceTimersByTime(1000);
44
+
45
+ // ...
46
+ });
47
+
48
+ test('plays video', () => {
49
+ const spy = jest.spyOn(video, 'play');
50
+
51
+ // ...
52
+ });
53
+ ```
@@ -0,0 +1,64 @@
1
+ # jest/no-restricted-matchers
2
+
3
+ 📝 Disallow specific matchers & modifiers.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ You may want to ban specific matchers & modifiers from being used.
8
+
9
+ ## Rule details
10
+
11
+ This rule bans specific matchers & modifiers from being used, and can suggest
12
+ alternatives.
13
+
14
+ ## Options
15
+
16
+ Bans are expressed in the form of a map, with the value being either a string
17
+ message to be shown, or `null` if the default rule message should be used.
18
+
19
+ Bans are checked against the start of the `expect` chain - this means that to
20
+ ban a specific matcher entirely you must specify all six permutations, but
21
+ allows you to ban modifiers as well.
22
+
23
+ By default, this map is empty, meaning no matchers or modifiers are banned.
24
+
25
+ For example:
26
+
27
+ ```json
28
+ {
29
+ "jest/no-restricted-matchers": [
30
+ "error",
31
+ {
32
+ "toBeFalsy": null,
33
+ "resolves": "Use `expect(await promise)` instead.",
34
+ "toHaveBeenCalledWith": null,
35
+ "not.toHaveBeenCalledWith": null,
36
+ "resolves.toHaveBeenCalledWith": null,
37
+ "rejects.toHaveBeenCalledWith": null,
38
+ "resolves.not.toHaveBeenCalledWith": null,
39
+ "rejects.not.toHaveBeenCalledWith": null
40
+ }
41
+ ]
42
+ }
43
+ ```
44
+
45
+ Examples of **incorrect** code for this rule with the above configuration
46
+
47
+ ```js
48
+ it('is false', () => {
49
+ // if this has a modifer (i.e. `not.toBeFalsy`), it would be considered fine
50
+ expect(a).toBeFalsy();
51
+ });
52
+
53
+ it('resolves', async () => {
54
+ // all uses of this modifier are disallowed, regardless of matcher
55
+ await expect(myPromise()).resolves.toBe(true);
56
+ });
57
+
58
+ describe('when an error happens', () => {
59
+ it('does not upload the file', async () => {
60
+ // all uses of this matcher are disallowed
61
+ expect(uploadFileMock).not.toHaveBeenCalledWith('file.name');
62
+ });
63
+ });
64
+ ```
@@ -0,0 +1,106 @@
1
+ # jest/no-standalone-expect
2
+
3
+ 📝 Disallow using `expect` outside of `it` or `test` blocks.
4
+
5
+ 💼 This rule is enabled in the ✅ `recommended`
6
+ [config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ Prevents `expect` statements outside of a `test` or `it` block. An `expect`
11
+ within a helper function (but outside of a `test` or `it` block) will not
12
+ trigger this rule.
13
+
14
+ ## Rule details
15
+
16
+ This rule aims to eliminate `expect` statements that will not be executed. An
17
+ `expect` inside of a `describe` block but outside of a `test` or `it` block or
18
+ outside a `describe` will not execute and therefore will trigger this rule. It
19
+ is viable, however, to have an `expect` in a helper function that is called from
20
+ within a `test` or `it` block so `expect` statements in a function will not
21
+ trigger this rule.
22
+
23
+ Statements like `expect.hasAssertions()` will NOT trigger this rule since these
24
+ calls will execute if they are not in a test block.
25
+
26
+ Examples of **incorrect** code for this rule:
27
+
28
+ ```js
29
+ // in describe
30
+ describe('a test', () => {
31
+ expect(1).toBe(1);
32
+ });
33
+
34
+ // below other tests
35
+ describe('a test', () => {
36
+ it('an it', () => {
37
+ expect(1).toBe(1);
38
+ });
39
+
40
+ expect(1).toBe(1);
41
+ });
42
+ ```
43
+
44
+ Examples of **correct** code for this rule:
45
+
46
+ ```js
47
+ // in it block
48
+ describe('a test', () => {
49
+ it('an it', () => {
50
+ expect(1).toBe(1);
51
+ });
52
+ });
53
+
54
+ // in helper function
55
+ describe('a test', () => {
56
+ const helper = () => {
57
+ expect(1).toBe(1);
58
+ };
59
+
60
+ it('an it', () => {
61
+ helper();
62
+ });
63
+ });
64
+
65
+ describe('a test', () => {
66
+ expect.hasAssertions(1);
67
+ });
68
+ ```
69
+
70
+ \*Note that this rule will not trigger if the helper function is never used even
71
+ though the `expect` will not execute. Rely on a rule like no-unused-vars for
72
+ this case.
73
+
74
+ ### Options
75
+
76
+ #### `additionalTestBlockFunctions`
77
+
78
+ This array can be used to specify the names of functions that should also be
79
+ treated as test blocks:
80
+
81
+ ```json
82
+ {
83
+ "rules": {
84
+ "jest/no-standalone-expect": [
85
+ "error",
86
+ { "additionalTestBlockFunctions": ["each.test"] }
87
+ ]
88
+ }
89
+ }
90
+ ```
91
+
92
+ The following is _correct_ when using the above configuration:
93
+
94
+ ```js
95
+ each([
96
+ [1, 1, 2],
97
+ [1, 2, 3],
98
+ [2, 1, 3],
99
+ ]).test('returns the result of adding %d to %d', (a, b, expected) => {
100
+ expect(a + b).toBe(expected);
101
+ });
102
+ ```
103
+
104
+ ## When Not To Use It
105
+
106
+ Don't use this rule on non-jest test files.
@@ -0,0 +1,42 @@
1
+ # jest/no-test-prefixes
2
+
3
+ 📝 Require using `.only` and `.skip` over `f` and `x`.
4
+
5
+ 💼 This rule is enabled in the ✅ `recommended`
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
+ Jest allows you to choose how you want to define focused and skipped tests, with
14
+ multiple permutations for each:
15
+
16
+ - **only & skip:** `it.only`, `test.only`, `describe.only`, `it.skip`,
17
+ `test.skip`, `describe.skip`.
18
+ - **'f' & 'x':** `fit`, `fdescribe`, `xit`, `xtest`, `xdescribe`.
19
+
20
+ This rule enforces usages from the **only & skip** list.
21
+
22
+ ## Rule details
23
+
24
+ This rule triggers a warning if you use one of the keywords from the **'f' &
25
+ 'x'** list to focus/skip a test.
26
+
27
+ ```js
28
+ /*eslint jest/no-test-prefixes: "error"*/
29
+
30
+ it.only('foo'); // valid
31
+ test.only('foo'); // valid
32
+ describe.only('foo'); // valid
33
+ it.skip('foo'); // valid
34
+ test.skip('foo'); // valid
35
+ describe.skip('foo'); // valid
36
+
37
+ fit('foo'); // invalid
38
+ fdescribe('foo'); // invalid
39
+ xit('foo'); // invalid
40
+ xtest('foo'); // invalid
41
+ xdescribe('foo'); // invalid
42
+ ```
@@ -0,0 +1,50 @@
1
+ # jest/no-test-return-statement
2
+
3
+ 📝 Disallow explicitly returning from tests.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ Tests in Jest should be void and not return values.
8
+
9
+ If you are returning Promises then you should update the test to use
10
+ `async/await`.
11
+
12
+ ## Rule details
13
+
14
+ This rule triggers a warning if you use a return statement inside a test body.
15
+
16
+ ```js
17
+ /*eslint jest/no-test-return-statement: "error"*/
18
+
19
+ // valid:
20
+
21
+ it('noop', function () {});
22
+
23
+ test('noop', () => {});
24
+
25
+ test('one arrow', () => expect(1).toBe(1));
26
+
27
+ test('empty');
28
+
29
+ test('one', () => {
30
+ expect(1).toBe(1);
31
+ });
32
+
33
+ it('one', function () {
34
+ expect(1).toBe(1);
35
+ });
36
+
37
+ it('returning a promise', async () => {
38
+ await new Promise(res => setTimeout(res, 100));
39
+ expect(1).toBe(1);
40
+ });
41
+
42
+ // invalid:
43
+ test('return an expect', () => {
44
+ return expect(1).toBe(1);
45
+ });
46
+
47
+ it('returning a promise', function () {
48
+ return new Promise(res => setTimeout(res, 100)).then(() => expect(1).toBe(1));
49
+ });
50
+ ```
@@ -0,0 +1,41 @@
1
+ # jest/no-unnecessary-assertion
2
+
3
+ 📝 Disallow unnecessary assertions based on types.
4
+
5
+ 💭 This rule requires
6
+ [type information](https://typescript-eslint.io/linting/typed-linting).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ When using TypeScript, runtime assertions based on types can often be omitted
11
+ provided that the types are accurate.
12
+
13
+ ## Rule details
14
+
15
+ This rule warns when you do an assertion about being `null`, `undefined`, or
16
+ `NaN` on something that cannot be those types, as that indicates either the
17
+ assertion can be removed or the types need to be adjusted.
18
+
19
+ The following patterns are considered warnings:
20
+
21
+ ```ts
22
+ expect('hello world'.match('sunshine') ?? []).toBeNull();
23
+
24
+ expect(User.findOrThrow(1)).toBeDefined();
25
+
26
+ expect(map.getOrInsert('key', 'default')).not.toBeUndefined();
27
+
28
+ expect(user.name).not.toBeNaN();
29
+ ```
30
+
31
+ The following patterns are not considered warnings:
32
+
33
+ ```ts
34
+ expect('hello world'.match('sunshine')).toBeNull();
35
+
36
+ expect(User.findOrNull(1)).toBeDefined();
37
+
38
+ expect(map.get('key')).not.toBeUndefined();
39
+
40
+ expect(user.age).not.toBeNaN();
41
+ ```
@@ -0,0 +1,41 @@
1
+ # jest/no-unneeded-async-expect-function
2
+
3
+ 📝 Disallow unnecessary async function wrapper for expected promises.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ `Jest` can handle fulfilled/rejected promisified function call normally but
11
+ occassionally, engineers wrap said function in another `async` function that is
12
+ excessively verbose and make the tests harder to read.
13
+
14
+ ## Rule details
15
+
16
+ This rule triggers a warning if `expect` is passed with an an `async` function
17
+ that has a single `await` call.
18
+
19
+ Examples of **incorrect** code for this rule
20
+
21
+ ```js
22
+ it('wrong1', async () => {
23
+ await expect(async () => {
24
+ await doSomethingAsync();
25
+ }).rejects.toThrow();
26
+ });
27
+
28
+ it('wrong2', async () => {
29
+ await expect(async function () {
30
+ await doSomethingAsync();
31
+ }).rejects.toThrow();
32
+ });
33
+ ```
34
+
35
+ Examples of **correct** code for this rule
36
+
37
+ ```js
38
+ it('right1', async () => {
39
+ await expect(doSomethingAsync()).rejects.toThrow();
40
+ });
41
+ ```
@@ -0,0 +1,74 @@
1
+ # jest/no-untyped-mock-factory
2
+
3
+ 📝 Disallow using `jest.mock()` factories without an explicit type parameter.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ By default, `jest.mock` and `jest.doMock` allow any type to be returned by a
11
+ mock factory. A generic type parameter can be used to enforce that the factory
12
+ returns an object with the same shape as the original module, or some other
13
+ strict type. Requiring a type makes it easier to use TypeScript to catch changes
14
+ needed in test mocks when the source module changes.
15
+
16
+ > **Warning**
17
+ >
18
+ > This rule expects to be run on TypeScript files **only**. If you are using a
19
+ > codebase that has a mix of JavaScript and TypeScript tests, you can use
20
+ > [overrides](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#how-do-overrides-work)
21
+ > to apply this rule to just your TypeScript test files.
22
+
23
+ ## Rule details
24
+
25
+ This rule triggers a warning if `mock()` or `doMock()` is used without a generic
26
+ type parameter or return type.
27
+
28
+ The following patterns are considered errors:
29
+
30
+ ```ts
31
+ jest.mock('../moduleName', () => {
32
+ return jest.fn(() => 42);
33
+ });
34
+
35
+ jest.mock('./module', () => ({
36
+ ...jest.requireActual('./module'),
37
+ foo: jest.fn(),
38
+ }));
39
+
40
+ jest.mock('random-num', () => {
41
+ return jest.fn(() => 42);
42
+ });
43
+ ```
44
+
45
+ The following patterns are not considered errors:
46
+
47
+ ```ts
48
+ // Uses typeof import()
49
+ jest.mock<typeof import('../moduleName')>('../moduleName', () => {
50
+ return jest.fn(() => 42);
51
+ });
52
+
53
+ jest.mock<typeof import('./module')>('./module', () => ({
54
+ ...jest.requireActual('./module'),
55
+ foo: jest.fn(),
56
+ }));
57
+
58
+ // Uses custom type
59
+ jest.mock<() => number>('random-num', () => {
60
+ return jest.fn(() => 42);
61
+ });
62
+
63
+ // No factory
64
+ jest.mock('random-num');
65
+
66
+ // Virtual mock
67
+ jest.mock(
68
+ '../moduleName',
69
+ () => {
70
+ return jest.fn(() => 42);
71
+ },
72
+ { virtual: true },
73
+ );
74
+ ```
@@ -0,0 +1,34 @@
1
+ # jest/padding-around-after-all-blocks
2
+
3
+ 📝 Enforce padding around `afterAll` blocks.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This rule enforces a line of padding before _and_ after 1 or more `afterAll`
13
+ statements.
14
+
15
+ Note that it doesn't add/enforce a padding line if it's the last statement in
16
+ its scope.
17
+
18
+ Examples of **incorrect** code for this rule:
19
+
20
+ ```js
21
+ const someText = 'abc';
22
+ afterAll(() => {});
23
+ describe('someText', () => {});
24
+ ```
25
+
26
+ Examples of **correct** code for this rule:
27
+
28
+ ```js
29
+ const someText = 'abc';
30
+
31
+ afterAll(() => {});
32
+
33
+ describe('someText', () => {});
34
+ ```
@@ -0,0 +1,38 @@
1
+ # jest/padding-around-after-each-blocks
2
+
3
+ 📝 Enforce padding around `afterEach` blocks.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This rule enforces a line of padding before _and_ after 1 or more `afterEach`
13
+ statements.
14
+
15
+ Note that it doesn't add/enforce a padding line if it's the last statement in
16
+ its scope.
17
+
18
+ Examples of **incorrect** code for this rule:
19
+
20
+ ```js
21
+ const something = 123;
22
+ afterEach(() => {
23
+ // more stuff
24
+ });
25
+ describe('foo', () => {});
26
+ ```
27
+
28
+ Examples of **correct** code for this rule:
29
+
30
+ ```js
31
+ const something = 123;
32
+
33
+ afterEach(() => {
34
+ // more stuff
35
+ });
36
+
37
+ describe('foo', () => {});
38
+ ```
@@ -0,0 +1,20 @@
1
+ # jest/padding-around-all
2
+
3
+ 📝 Enforce padding around Jest functions.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This is a meta rule that simply enables all of the following rules:
13
+
14
+ - [padding-around-after-all-blocks](padding-around-after-all-blocks.md)
15
+ - [padding-around-after-each-blocks](padding-around-after-each-blocks.md)
16
+ - [padding-around-before-all-blocks](padding-around-before-all-blocks.md)
17
+ - [padding-around-before-each-blocks](padding-around-before-each-blocks.md)
18
+ - [padding-around-expect-groups](padding-around-expect-groups.md)
19
+ - [padding-around-describe-blocks](padding-around-describe-blocks.md)
20
+ - [padding-around-test-blocks](padding-around-test-blocks.md)
@@ -0,0 +1,37 @@
1
+ # jest/padding-around-before-all-blocks
2
+
3
+ 📝 Enforce padding around `beforeAll` blocks.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This rule enforces a line of padding before _and_ after `beforeAll` statements.
13
+
14
+ Note that it doesn't add/enforce a padding line if it's the last statement in
15
+ its scope.
16
+
17
+ Examples of **incorrect** code for this rule:
18
+
19
+ ```js
20
+ const something = 123;
21
+ beforeAll(() => {
22
+ // more stuff
23
+ });
24
+ describe('foo', () => {});
25
+ ```
26
+
27
+ Examples of **correct** code for this rule:
28
+
29
+ ```js
30
+ const something = 123;
31
+
32
+ beforeAll(() => {
33
+ // more stuff
34
+ });
35
+
36
+ describe('foo', () => {});
37
+ ```
@@ -0,0 +1,38 @@
1
+ # jest/padding-around-before-each-blocks
2
+
3
+ 📝 Enforce padding around `beforeEach` blocks.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This rule enforces a line of padding before _and_ after 1 or more `beforeEach`
13
+ statements
14
+
15
+ Note that it doesn't add/enforce a padding line if it's the last statement in
16
+ its scope
17
+
18
+ Examples of **incorrect** code for this rule:
19
+
20
+ ```js
21
+ const something = 123;
22
+ beforeEach(() => {
23
+ // more stuff
24
+ });
25
+ describe('foo', () => {});
26
+ ```
27
+
28
+ Examples of **correct** code for this rule:
29
+
30
+ ```js
31
+ const something = 123;
32
+
33
+ beforeEach(() => {
34
+ // more stuff
35
+ });
36
+
37
+ describe('foo', () => {});
38
+ ```
@@ -0,0 +1,42 @@
1
+ # jest/padding-around-describe-blocks
2
+
3
+ 📝 Enforce padding around `describe` blocks.
4
+
5
+ 🔧 This rule is automatically fixable by the
6
+ [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
7
+
8
+ <!-- end auto-generated rule header -->
9
+
10
+ ## Rule Details
11
+
12
+ This rule enforces a line of padding before _and_ after 1 or more `describe`
13
+ statements
14
+
15
+ Note that it doesn't add/enforce a padding line if it's the last statement in
16
+ its scope
17
+
18
+ Examples of **incorrect** code for this rule:
19
+
20
+ ```js
21
+ const thing = 123;
22
+ describe('foo', () => {
23
+ // stuff
24
+ });
25
+ describe('bar', () => {
26
+ // more stuff
27
+ });
28
+ ```
29
+
30
+ Examples of **correct** code for this rule:
31
+
32
+ ```js
33
+ const thing = 123;
34
+
35
+ describe('foo', () => {
36
+ // stuff
37
+ });
38
+
39
+ describe('bar', () => {
40
+ // more stuff
41
+ });
42
+ ```