@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,52 @@
1
+ # jest/no-export
2
+
3
+ 📝 Disallow using `exports` in files containing tests.
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 using `exports` if a file has one or more tests in it.
11
+
12
+ ## Rule details
13
+
14
+ This rule aims to eliminate duplicate runs of tests by exporting things from
15
+ test files. If you import from a test file, then all the tests in that file will
16
+ be run in each imported instance, so bottom line, don't export from a test, but
17
+ instead move helper functions into a separate file when they need to be shared
18
+ across tests.
19
+
20
+ Examples of **incorrect** code for this rule:
21
+
22
+ ```js
23
+ export function myHelper() {}
24
+
25
+ module.exports = function () {};
26
+
27
+ module.exports = {
28
+ something: 'that should be moved to a non-test file',
29
+ };
30
+
31
+ describe('a test', () => {
32
+ expect(1).toBe(1);
33
+ });
34
+ ```
35
+
36
+ Examples of **correct** code for this rule:
37
+
38
+ ```js
39
+ function myHelper() {}
40
+
41
+ const myThing = {
42
+ something: 'that can live here',
43
+ };
44
+
45
+ describe('a test', () => {
46
+ expect(1).toBe(1);
47
+ });
48
+ ```
49
+
50
+ ## When Not To Use It
51
+
52
+ Don't use this rule on non-jest test files.
@@ -0,0 +1,67 @@
1
+ # jest/no-focused-tests
2
+
3
+ 📝 Disallow focused tests.
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 manually fixable by
9
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
10
+
11
+ <!-- end auto-generated rule header -->
12
+
13
+ <!-- prettier-ignore -->
14
+ Jest has a feature that allows you to focus tests by appending `.only` or
15
+ prepending `f` to a test-suite or a test-case. This feature is really helpful to
16
+ debug a failing test, so you don’t have to execute all of your tests. After you
17
+ have fixed your test and before committing the changes you have to remove
18
+ `.only` to ensure all tests are executed on your build system.
19
+
20
+ This rule reminds you to remove `.only` from your tests by raising a warning
21
+ whenever you are using the exclusivity feature.
22
+
23
+ ## Rule details
24
+
25
+ This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
26
+ and `fit` occurrences within the source code. Of course there are some
27
+ edge-cases which can’t be detected by this rule e.g.:
28
+
29
+ ```js
30
+ const describeOnly = describe.only;
31
+ describeOnly.apply(describe);
32
+ ```
33
+
34
+ The following patterns are considered warnings:
35
+
36
+ ```js
37
+ describe.only('foo', () => {});
38
+ it.only('foo', () => {});
39
+ describe['only']('bar', () => {});
40
+ it['only']('bar', () => {});
41
+ test.only('foo', () => {});
42
+ test['only']('bar', () => {});
43
+ fdescribe('foo', () => {});
44
+ fit('foo', () => {});
45
+ fit.each`
46
+ table
47
+ `();
48
+ ```
49
+
50
+ These patterns would not be considered warnings:
51
+
52
+ ```js
53
+ describe('foo', () => {});
54
+ it('foo', () => {});
55
+ describe.skip('bar', () => {});
56
+ it.skip('bar', () => {});
57
+ test('foo', () => {});
58
+ test.skip('bar', () => {});
59
+ it.each()();
60
+ it.each`
61
+ table
62
+ `();
63
+ test.each()();
64
+ test.each`
65
+ table
66
+ `();
67
+ ```
@@ -0,0 +1,178 @@
1
+ # jest/no-hooks
2
+
3
+ 📝 Disallow setup and teardown hooks.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ Jest provides global functions for setup and teardown tasks, which are called
8
+ before/after each test case and each test suite. The use of these hooks promotes
9
+ shared state between tests.
10
+
11
+ ## Rule details
12
+
13
+ This rule reports for the following function calls:
14
+
15
+ - `beforeAll`
16
+ - `beforeEach`
17
+ - `afterAll`
18
+ - `afterEach`
19
+
20
+ Examples of **incorrect** code for this rule:
21
+
22
+ ```js
23
+ /* eslint jest/no-hooks: "error" */
24
+
25
+ function setupFoo(options) {
26
+ /* ... */
27
+ }
28
+
29
+ function setupBar(options) {
30
+ /* ... */
31
+ }
32
+
33
+ describe('foo', () => {
34
+ let foo;
35
+
36
+ beforeEach(() => {
37
+ foo = setupFoo();
38
+ });
39
+
40
+ afterEach(() => {
41
+ foo = null;
42
+ });
43
+
44
+ it('does something', () => {
45
+ expect(foo.doesSomething()).toBe(true);
46
+ });
47
+
48
+ describe('with bar', () => {
49
+ let bar;
50
+
51
+ beforeEach(() => {
52
+ bar = setupBar();
53
+ });
54
+
55
+ afterEach(() => {
56
+ bar = null;
57
+ });
58
+
59
+ it('does something with bar', () => {
60
+ expect(foo.doesSomething(bar)).toBe(true);
61
+ });
62
+ });
63
+ });
64
+ ```
65
+
66
+ Examples of **correct** code for this rule:
67
+
68
+ ```js
69
+ /* eslint jest/no-hooks: "error" */
70
+
71
+ function setupFoo(options) {
72
+ /* ... */
73
+ }
74
+
75
+ function setupBar(options) {
76
+ /* ... */
77
+ }
78
+
79
+ describe('foo', () => {
80
+ it('does something', () => {
81
+ const foo = setupFoo();
82
+ expect(foo.doesSomething()).toBe(true);
83
+ });
84
+
85
+ it('does something with bar', () => {
86
+ const foo = setupFoo();
87
+ const bar = setupBar();
88
+ expect(foo.doesSomething(bar)).toBe(true);
89
+ });
90
+ });
91
+ ```
92
+
93
+ ## Options
94
+
95
+ ```json
96
+ {
97
+ "jest/no-hooks": [
98
+ "error",
99
+ {
100
+ "allow": ["afterEach", "afterAll"]
101
+ }
102
+ ]
103
+ }
104
+ ```
105
+
106
+ ### `allow`
107
+
108
+ This array option controls which Jest hooks are checked by this rule. There are
109
+ four possible values:
110
+
111
+ - `"beforeAll"`
112
+ - `"beforeEach"`
113
+ - `"afterAll"`
114
+ - `"afterEach"`
115
+
116
+ By default, none of these options are enabled (the equivalent of
117
+ `{ "allow": [] }`).
118
+
119
+ Examples of **incorrect** code for the `{ "allow": ["afterEach"] }` option:
120
+
121
+ ```js
122
+ /* eslint jest/no-hooks: ["error", { "allow": ["afterEach"] }] */
123
+
124
+ function setupFoo(options) {
125
+ /* ... */
126
+ }
127
+
128
+ let foo;
129
+
130
+ beforeEach(() => {
131
+ foo = setupFoo();
132
+ });
133
+
134
+ afterEach(() => {
135
+ jest.resetModules();
136
+ });
137
+
138
+ test('foo does this', () => {
139
+ // ...
140
+ });
141
+
142
+ test('foo does that', () => {
143
+ // ...
144
+ });
145
+ ```
146
+
147
+ Examples of **correct** code for the `{ "allow": ["afterEach"] }` option:
148
+
149
+ ```js
150
+ /* eslint jest/no-hooks: ["error", { "allow": ["afterEach"] }] */
151
+
152
+ function setupFoo(options) {
153
+ /* ... */
154
+ }
155
+
156
+ afterEach(() => {
157
+ jest.resetModules();
158
+ });
159
+
160
+ test('foo does this', () => {
161
+ const foo = setupFoo();
162
+ // ...
163
+ });
164
+
165
+ test('foo does that', () => {
166
+ const foo = setupFoo();
167
+ // ...
168
+ });
169
+ ```
170
+
171
+ ## When Not To Use It
172
+
173
+ If you prefer using the setup and teardown hooks provided by Jest, you can
174
+ safely disable this rule.
175
+
176
+ ## Further Reading
177
+
178
+ - [Jest docs - Setup and Teardown](https://jestjs.io/docs/setup-teardown)
@@ -0,0 +1,59 @@
1
+ # jest/no-identical-title
2
+
3
+ 📝 Disallow identical titles.
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
+ Having identical titles for two different tests or test suites may create
11
+ confusion. For example, when a test with the same title as another test in the
12
+ same test suite fails, it is harder to know which one failed and thus harder to
13
+ fix.
14
+
15
+ ## Rule details
16
+
17
+ This rule looks at the title of every test and test suite. It will report when
18
+ two test suites or two test cases at the same level of a test suite have the
19
+ same title.
20
+
21
+ The following patterns are considered warnings:
22
+
23
+ ```js
24
+ describe('foo', () => {
25
+ it('should do bar', () => {});
26
+ it('should do bar', () => {}); // Has the same title as the previous test
27
+
28
+ describe('baz', () => {
29
+ // ...
30
+ });
31
+
32
+ describe('baz', () => {
33
+ // Has the same title as a previous test suite
34
+ // ...
35
+ });
36
+ });
37
+ ```
38
+
39
+ These patterns would not be considered warnings:
40
+
41
+ ```js
42
+ describe('foo', () => {
43
+ it('should do foo', () => {});
44
+ it('should do bar', () => {});
45
+
46
+ // Has the same name as a parent test suite, which is fine
47
+ describe('foo', () => {
48
+ // Has the same name as a test in a parent test suite, which is fine
49
+ it('should do foo', () => {});
50
+ it('should work', () => {});
51
+ });
52
+
53
+ describe('baz', () => {
54
+ // Has the same title as a previous test suite
55
+ // Has the same name as a test in a sibling test suite, which is fine
56
+ it('should work', () => {});
57
+ });
58
+ });
59
+ ```
@@ -0,0 +1,67 @@
1
+ # jest/no-interpolation-in-snapshots
2
+
3
+ 📝 Disallow string interpolation inside snapshots.
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 the use of string interpolations in snapshots.
11
+
12
+ ## Rule details
13
+
14
+ Interpolation prevents snapshots from being updated. Instead, properties should
15
+ be overloaded with a matcher by using
16
+ [property matchers](https://jestjs.io/docs/en/snapshot-testing#property-matchers).
17
+
18
+ Examples of **incorrect** code for this rule:
19
+
20
+ ```js
21
+ expect(something).toMatchInlineSnapshot(
22
+ `Object {
23
+ property: ${interpolated}
24
+ }`,
25
+ );
26
+
27
+ expect(something).toMatchInlineSnapshot(
28
+ { other: expect.any(Number) },
29
+ `Object {
30
+ other: Any<Number>,
31
+ property: ${interpolated}
32
+ }`,
33
+ );
34
+
35
+ expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
36
+ `${interpolated}`,
37
+ );
38
+ ```
39
+
40
+ Examples of **correct** code for this rule:
41
+
42
+ ```js
43
+ expect(something).toMatchInlineSnapshot();
44
+
45
+ expect(something).toMatchInlineSnapshot(
46
+ `Object {
47
+ property: 1
48
+ }`,
49
+ );
50
+
51
+ expect(something).toMatchInlineSnapshot(
52
+ { property: expect.any(Date) },
53
+ `Object {
54
+ property: Any<Date>
55
+ }`,
56
+ );
57
+
58
+ expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot();
59
+
60
+ expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
61
+ `Error Message`,
62
+ );
63
+ ```
64
+
65
+ ## When Not To Use It
66
+
67
+ Don't use this rule on non-jest test files.
@@ -0,0 +1,69 @@
1
+ # jest/no-jasmine-globals
2
+
3
+ 📝 Disallow Jasmine globals.
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` uses `jasmine` as a test runner. A side effect of this is that both a
14
+ `jasmine` object, and some jasmine-specific globals, are exposed to the test
15
+ environment. Most functionality offered by Jasmine has been ported to Jest, and
16
+ the Jasmine globals will stop working in the future. Developers should therefore
17
+ migrate to Jest's documented API instead of relying on the undocumented Jasmine
18
+ API.
19
+
20
+ ## Rule details
21
+
22
+ This rule reports on any usage of Jasmine globals, which is not ported to Jest,
23
+ and suggests alternatives from Jest's own API.
24
+
25
+ ## Examples
26
+
27
+ The following patterns are considered warnings:
28
+
29
+ ```js
30
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
31
+
32
+ test('my test', () => {
33
+ pending();
34
+ });
35
+
36
+ test('my test', () => {
37
+ fail();
38
+ });
39
+
40
+ test('my test', () => {
41
+ spyOn(some, 'object');
42
+ });
43
+
44
+ test('my test', () => {
45
+ jasmine.createSpy();
46
+ });
47
+
48
+ test('my test', () => {
49
+ expect('foo').toEqual(jasmine.anything());
50
+ });
51
+ ```
52
+
53
+ The following patterns would not be considered warnings:
54
+
55
+ ```js
56
+ jest.setTimeout(5000);
57
+
58
+ test('my test', () => {
59
+ jest.spyOn(some, 'object');
60
+ });
61
+
62
+ test('my test', () => {
63
+ jest.fn();
64
+ });
65
+
66
+ test('my test', () => {
67
+ expect('foo').toEqual(expect.anything());
68
+ });
69
+ ```
@@ -0,0 +1,180 @@
1
+ # jest/no-large-snapshots
2
+
3
+ 📝 Disallow large snapshots.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ When using Jest's snapshot capability one should be mindful of the size of
8
+ created snapshots. As a general best practice snapshots should be limited in
9
+ size in order to be more manageable and reviewable. A stored snapshot is only as
10
+ good as its review and as such keeping it short, sweet, and readable is
11
+ important to allow for thorough reviews.
12
+
13
+ ## Usage
14
+
15
+ Because Jest snapshots are written with back-ticks (\` \`) which are only valid
16
+ with
17
+ [ES2015 onwards](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)
18
+ you should set `parserOptions` in your config to at least allow ES2015 in order
19
+ to use this rule:
20
+
21
+ ```js
22
+ module.exports = {
23
+ parserOptions: {
24
+ ecmaVersion: 2015,
25
+ },
26
+ };
27
+ ```
28
+
29
+ In order to check external snapshots, you must also have `eslint` check files
30
+ with the `.snap` extension by either passing `--ext snap` on the command line or
31
+ by explicitly specifying `.snap` in `overrides`.
32
+
33
+ ## Rule details
34
+
35
+ This rule looks at all Jest inline and external snapshots (files with `.snap`
36
+ extension) and validates that each stored snapshot within those files does not
37
+ exceed 50 lines (by default, this is configurable as explained in `Options`
38
+ section below).
39
+
40
+ Example of **incorrect** code for this rule:
41
+
42
+ ```js
43
+ exports[`a large snapshot 1`] = `
44
+ line 1
45
+ line 2
46
+ line 3
47
+ line 4
48
+ line 5
49
+ line 6
50
+ line 7
51
+ line 8
52
+ line 9
53
+ line 10
54
+ line 11
55
+ line 12
56
+ line 13
57
+ line 14
58
+ line 15
59
+ line 16
60
+ line 17
61
+ line 18
62
+ line 19
63
+ line 20
64
+ line 21
65
+ line 22
66
+ line 23
67
+ line 24
68
+ line 25
69
+ line 26
70
+ line 27
71
+ line 28
72
+ line 29
73
+ line 30
74
+ line 31
75
+ line 32
76
+ line 33
77
+ line 34
78
+ line 35
79
+ line 36
80
+ line 37
81
+ line 38
82
+ line 39
83
+ line 40
84
+ line 41
85
+ line 42
86
+ line 43
87
+ line 44
88
+ line 45
89
+ line 46
90
+ line 47
91
+ line 48
92
+ line 49
93
+ line 50
94
+ line 51
95
+ `;
96
+ ```
97
+
98
+ Example of **correct** code for this rule:
99
+
100
+ ```js
101
+ exports[`a more manageable and readable snapshot 1`] = `
102
+ line 1
103
+ line 2
104
+ line 3
105
+ line 4
106
+ `;
107
+ ```
108
+
109
+ ## Options
110
+
111
+ This rule has options for modifying the max number of lines allowed for a
112
+ snapshot:
113
+
114
+ In an `eslintrc` file:
115
+
116
+ ```json
117
+ {
118
+ "rules": {
119
+ "jest/no-large-snapshots": ["warn", { "maxSize": 12, "inlineMaxSize": 6 }]
120
+ }
121
+ }
122
+ ```
123
+
124
+ Max number of lines allowed could be defined by snapshot type (Inline and
125
+ External). Use `inlineMaxSize` for
126
+ [Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
127
+ size and `maxSize` for
128
+ [External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
129
+ If only `maxSize` is provided on options, the value of `maxSize` will be used
130
+ for both snapshot types (Inline and External).
131
+
132
+ Since `eslint-disable` comments are not preserved by Jest when updating
133
+ snapshots, you can use the `allowedSnapshots` option to have specific snapshots
134
+ allowed regardless of their size.
135
+
136
+ This option takes a map, with the key being the absolute filepath to a snapshot
137
+ file, and the value an array of values made up of strings and regular
138
+ expressions to compare to the names of the snapshots in the `.snap` file when
139
+ checking if the snapshots size should be allowed.
140
+
141
+ Note that regular expressions can only be passed in via `.eslintrc.js` as
142
+ instances of `RegExp`.
143
+
144
+ In an `.eslintrc.js` file:
145
+
146
+ ```javascript
147
+ module.exports = {
148
+ rules: {
149
+ 'jest/no-large-snapshots': [
150
+ 'error',
151
+ {
152
+ allowedSnapshots: {
153
+ '/path/to/file.js.snap': ['snapshot name 1', /a big snapshot \d+/],
154
+ },
155
+ },
156
+ ],
157
+ },
158
+ };
159
+ ```
160
+
161
+ Since absolute paths are typically not very portable, you can use the builtin
162
+ `path.resolve` function to expand relative paths into absolutes like so:
163
+
164
+ ```javascript
165
+ const path = require('path');
166
+
167
+ module.exports = {
168
+ rules: {
169
+ 'jest/no-large-snapshots': [
170
+ 'error',
171
+ {
172
+ allowedSnapshots: {
173
+ [path.resolve('test/__snapshots__/get.js.snap')]: ['full request'],
174
+ [path.resolve('test/__snapshots__/put.js.snap')]: ['full request'],
175
+ },
176
+ },
177
+ ],
178
+ },
179
+ };
180
+ ```
@@ -0,0 +1,34 @@
1
+ # jest/no-mocks-import
2
+
3
+ 📝 Disallow manually importing from `__mocks__`.
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
+ When using `jest.mock`, your tests (just like the code being tested) should
11
+ import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
12
+ confusion, because you will have multiple instances of the mocked module:
13
+
14
+ ```js
15
+ jest.mock('./x');
16
+ const x1 = require('./x');
17
+ const x2 = require('./__mocks__/x');
18
+
19
+ test('x', () => {
20
+ expect(x1).toBe(x2); // fails! They are both instances of `./__mocks__/x`, but not referentially equal
21
+ });
22
+ ```
23
+
24
+ ## Rule details
25
+
26
+ This rule reports imports from a path containing a `__mocks__` component.
27
+
28
+ Example violations:
29
+
30
+ ```js
31
+ import thing from './__mocks__/index';
32
+ require('./__mocks__/index');
33
+ require('__mocks__');
34
+ ```