eslint-plugin-jest 27.2.1 → 27.2.2

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 (77) hide show
  1. package/README.md +1 -1
  2. package/docs/rules/no-alias-methods.md +1 -1
  3. package/docs/rules/no-hooks.md +1 -1
  4. package/docs/rules/no-large-snapshots.md +4 -0
  5. package/docs/rules/require-hook.md +2 -6
  6. package/docs/rules/valid-expect.md +2 -2
  7. package/lib/index.js +2 -0
  8. package/lib/processors/__tests__/snapshot-processor.test.js +36 -0
  9. package/lib/rules/__tests__/consistent-test-it.test.js +921 -0
  10. package/lib/rules/__tests__/expect-expect.test.js +347 -0
  11. package/lib/rules/__tests__/fixtures/class.ts +13 -0
  12. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  13. package/lib/rules/__tests__/fixtures/foo.ts +1 -0
  14. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +530 -0
  15. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +530 -0
  16. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  17. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +6 -0
  18. package/lib/rules/__tests__/fixtures/tsconfig.json +16 -0
  19. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  20. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  21. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +15 -0
  22. package/lib/rules/__tests__/max-expects.test.js +330 -0
  23. package/lib/rules/__tests__/max-nested-describe.test.js +247 -0
  24. package/lib/rules/__tests__/no-alias-methods.test.js +190 -0
  25. package/lib/rules/__tests__/no-commented-out-tests.test.js +213 -0
  26. package/lib/rules/__tests__/no-conditional-expect.test.js +696 -0
  27. package/lib/rules/__tests__/no-conditional-in-test.test.js +777 -0
  28. package/lib/rules/__tests__/no-deprecated-functions.test.js +119 -0
  29. package/lib/rules/__tests__/no-disabled-tests.test.js +241 -0
  30. package/lib/rules/__tests__/no-done-callback.test.js +424 -0
  31. package/lib/rules/__tests__/no-duplicate-hooks.test.js +469 -0
  32. package/lib/rules/__tests__/no-export.test.js +107 -0
  33. package/lib/rules/__tests__/no-focused-tests.test.js +373 -0
  34. package/lib/rules/__tests__/no-hooks.test.js +90 -0
  35. package/lib/rules/__tests__/no-identical-title.test.js +270 -0
  36. package/lib/rules/__tests__/no-if.test.js +787 -0
  37. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +58 -0
  38. package/lib/rules/__tests__/no-jasmine-globals.test.js +206 -0
  39. package/lib/rules/__tests__/no-large-snapshots.test.js +237 -0
  40. package/lib/rules/__tests__/no-mocks-import.test.js +73 -0
  41. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +103 -0
  42. package/lib/rules/__tests__/no-restricted-matchers.test.js +244 -0
  43. package/lib/rules/__tests__/no-standalone-expect.test.js +230 -0
  44. package/lib/rules/__tests__/no-test-prefixes.test.js +206 -0
  45. package/lib/rules/__tests__/no-test-return-statement.test.js +122 -0
  46. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +149 -0
  47. package/lib/rules/__tests__/prefer-called-with.test.js +40 -0
  48. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +200 -0
  49. package/lib/rules/__tests__/prefer-each.test.js +295 -0
  50. package/lib/rules/__tests__/prefer-equality-matcher.test.js +184 -0
  51. package/lib/rules/__tests__/prefer-expect-assertions.test.js +1437 -0
  52. package/lib/rules/__tests__/prefer-expect-resolves.test.js +96 -0
  53. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +678 -0
  54. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +218 -0
  55. package/lib/rules/__tests__/prefer-lowercase-title.test.js +619 -0
  56. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +360 -0
  57. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +784 -0
  58. package/lib/rules/__tests__/prefer-spy-on.test.js +100 -0
  59. package/lib/rules/__tests__/prefer-strict-equal.test.js +46 -0
  60. package/lib/rules/__tests__/prefer-to-be.test.js +438 -0
  61. package/lib/rules/__tests__/prefer-to-contain.test.js +301 -0
  62. package/lib/rules/__tests__/prefer-to-have-length.test.js +99 -0
  63. package/lib/rules/__tests__/prefer-todo.test.js +78 -0
  64. package/lib/rules/__tests__/require-hook.test.js +403 -0
  65. package/lib/rules/__tests__/require-to-throw-message.test.js +108 -0
  66. package/lib/rules/__tests__/require-top-level-describe.test.js +236 -0
  67. package/lib/rules/__tests__/test-utils.js +11 -0
  68. package/lib/rules/__tests__/unbound-method.test.js +518 -0
  69. package/lib/rules/__tests__/valid-describe-callback.test.js +305 -0
  70. package/lib/rules/__tests__/valid-expect-in-promise.test.js +1583 -0
  71. package/lib/rules/__tests__/valid-expect.test.js +894 -0
  72. package/lib/rules/__tests__/valid-title.test.js +1147 -0
  73. package/lib/rules/utils/__tests__/detectJestVersion.test.js +221 -0
  74. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +809 -0
  75. package/lib/rules/utils/accessors.js +4 -0
  76. package/lib/rules/utils/misc.js +36 -20
  77. package/package.json +12 -8
@@ -0,0 +1,347 @@
1
+ "use strict";
2
+
3
+ var _utils = require("@typescript-eslint/utils");
4
+ var _dedent = _interopRequireDefault(require("dedent"));
5
+ var _expectExpect = _interopRequireDefault(require("../expect-expect"));
6
+ var _testUtils = require("./test-utils");
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ const ruleTester = new _utils.TSESLint.RuleTester({
9
+ parser: _testUtils.espreeParser,
10
+ parserOptions: {
11
+ ecmaVersion: 2015
12
+ }
13
+ });
14
+ ruleTester.run('expect-expect', _expectExpect.default, {
15
+ valid: ['it.todo("will test something eventually")', 'test.todo("will test something eventually")', "['x']();", 'it("should pass", () => expect(true).toBeDefined())', 'test("should pass", () => expect(true).toBeDefined())', 'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))', 'it("should pass", myTest); function myTest() { expect(true).toBeDefined() }', {
16
+ code: (0, _dedent.default)`
17
+ test('should pass', () => {
18
+ expect(true).toBeDefined();
19
+ foo(true).toBe(true);
20
+ });
21
+ `,
22
+ options: [{
23
+ assertFunctionNames: ['expect', 'foo']
24
+ }]
25
+ }, {
26
+ code: 'it("should return undefined",() => expectSaga(mySaga).returns());',
27
+ options: [{
28
+ assertFunctionNames: ['expectSaga']
29
+ }]
30
+ }, {
31
+ code: "test('verifies expect method call', () => expect$(123));",
32
+ options: [{
33
+ assertFunctionNames: ['expect\\$']
34
+ }]
35
+ }, {
36
+ code: "test('verifies expect method call', () => new Foo().expect(123));",
37
+ options: [{
38
+ assertFunctionNames: ['Foo.expect']
39
+ }]
40
+ }, {
41
+ code: (0, _dedent.default)`
42
+ test('verifies deep expect method call', () => {
43
+ tester.foo().expect(123);
44
+ });
45
+ `,
46
+ options: [{
47
+ assertFunctionNames: ['tester.foo.expect']
48
+ }]
49
+ }, {
50
+ code: (0, _dedent.default)`
51
+ test('verifies chained expect method call', () => {
52
+ tester
53
+ .foo()
54
+ .bar()
55
+ .expect(456);
56
+ });
57
+ `,
58
+ options: [{
59
+ assertFunctionNames: ['tester.foo.bar.expect']
60
+ }]
61
+ }, {
62
+ code: (0, _dedent.default)`
63
+ test("verifies the function call", () => {
64
+ td.verify(someFunctionCall())
65
+ })
66
+ `,
67
+ options: [{
68
+ assertFunctionNames: ['td.verify']
69
+ }]
70
+ }, {
71
+ code: 'it("should pass", () => expect(true).toBeDefined())',
72
+ options: [{
73
+ assertFunctionNames: undefined,
74
+ additionalTestBlockFunctions: undefined
75
+ }]
76
+ }, {
77
+ code: (0, _dedent.default)`
78
+ theoretically('the number {input} is correctly translated to string', theories, theory => {
79
+ const output = NumberToLongString(theory.input);
80
+ expect(output).toBe(theory.expected);
81
+ })
82
+ `,
83
+ options: [{
84
+ additionalTestBlockFunctions: ['theoretically']
85
+ }]
86
+ }],
87
+ invalid: [{
88
+ code: 'it("should fail", () => {});',
89
+ errors: [{
90
+ messageId: 'noAssertions',
91
+ type: _utils.AST_NODE_TYPES.CallExpression
92
+ }]
93
+ }, {
94
+ code: 'it("should fail", myTest); function myTest() {}',
95
+ errors: [{
96
+ messageId: 'noAssertions',
97
+ type: _utils.AST_NODE_TYPES.CallExpression
98
+ }]
99
+ }, {
100
+ code: 'test("should fail", () => {});',
101
+ errors: [{
102
+ messageId: 'noAssertions',
103
+ type: _utils.AST_NODE_TYPES.CallExpression
104
+ }]
105
+ }, {
106
+ code: 'test.skip("should fail", () => {});',
107
+ errors: [{
108
+ messageId: 'noAssertions',
109
+ type: _utils.AST_NODE_TYPES.CallExpression
110
+ }]
111
+ }, {
112
+ code: 'afterEach(() => {});',
113
+ options: [{
114
+ additionalTestBlockFunctions: ['afterEach']
115
+ }],
116
+ errors: [{
117
+ messageId: 'noAssertions',
118
+ type: _utils.AST_NODE_TYPES.CallExpression
119
+ }]
120
+ }, {
121
+ code: (0, _dedent.default)`
122
+ theoretically('the number {input} is correctly translated to string', theories, theory => {
123
+ const output = NumberToLongString(theory.input);
124
+ })
125
+ `,
126
+ options: [{
127
+ additionalTestBlockFunctions: ['theoretically']
128
+ }],
129
+ errors: [{
130
+ messageId: 'noAssertions',
131
+ type: _utils.AST_NODE_TYPES.CallExpression
132
+ }]
133
+ }, {
134
+ code: 'it("should fail", () => { somePromise.then(() => {}); });',
135
+ errors: [{
136
+ messageId: 'noAssertions',
137
+ type: _utils.AST_NODE_TYPES.CallExpression
138
+ }]
139
+ }, {
140
+ code: 'test("should fail", () => { foo(true).toBe(true); })',
141
+ options: [{
142
+ assertFunctionNames: ['expect']
143
+ }],
144
+ errors: [{
145
+ messageId: 'noAssertions',
146
+ type: _utils.AST_NODE_TYPES.CallExpression
147
+ }]
148
+ }, {
149
+ code: 'it("should also fail",() => expectSaga(mySaga).returns());',
150
+ options: [{
151
+ assertFunctionNames: ['expect']
152
+ }],
153
+ errors: [{
154
+ messageId: 'noAssertions',
155
+ type: _utils.AST_NODE_TYPES.CallExpression
156
+ }]
157
+ }]
158
+ });
159
+
160
+ // {
161
+ // code: `test('wildcard chained function', () => tester.foo().expect(123));`,
162
+ // options: [{ assertFunctionNames: ['tester.*.expect'] }],
163
+ // },
164
+
165
+ ruleTester.run('wildcards', _expectExpect.default, {
166
+ valid: [{
167
+ code: "test('should pass *', () => expect404ToBeLoaded());",
168
+ options: [{
169
+ assertFunctionNames: ['expect*']
170
+ }]
171
+ }, {
172
+ code: "test('should pass *', () => expect.toHaveStatus404());",
173
+ options: [{
174
+ assertFunctionNames: ['expect.**']
175
+ }]
176
+ }, {
177
+ code: "test('should pass', () => tester.foo().expect(123));",
178
+ options: [{
179
+ assertFunctionNames: ['tester.*.expect']
180
+ }]
181
+ }, {
182
+ code: "test('should pass **', () => tester.foo().expect(123));",
183
+ options: [{
184
+ assertFunctionNames: ['**']
185
+ }]
186
+ }, {
187
+ code: "test('should pass *', () => tester.foo().expect(123));",
188
+ options: [{
189
+ assertFunctionNames: ['*']
190
+ }]
191
+ }, {
192
+ code: "test('should pass', () => tester.foo().expect(123));",
193
+ options: [{
194
+ assertFunctionNames: ['tester.**']
195
+ }]
196
+ }, {
197
+ code: "test('should pass', () => tester.foo().expect(123));",
198
+ options: [{
199
+ assertFunctionNames: ['tester.*']
200
+ }]
201
+ }, {
202
+ code: "test('should pass', () => tester.foo().bar().expectIt(456));",
203
+ options: [{
204
+ assertFunctionNames: ['tester.**.expect*']
205
+ }]
206
+ }, {
207
+ code: "test('should pass', () => request.get().foo().expect(456));",
208
+ options: [{
209
+ assertFunctionNames: ['request.**.expect']
210
+ }]
211
+ }, {
212
+ code: "test('should pass', () => request.get().foo().expect(456));",
213
+ options: [{
214
+ assertFunctionNames: ['request.**.e*e*t']
215
+ }]
216
+ }],
217
+ invalid: [{
218
+ code: "test('should fail', () => request.get().foo().expect(456));",
219
+ options: [{
220
+ assertFunctionNames: ['request.*.expect']
221
+ }],
222
+ errors: [{
223
+ messageId: 'noAssertions',
224
+ type: _utils.AST_NODE_TYPES.CallExpression
225
+ }]
226
+ }, {
227
+ code: "test('should fail', () => request.get().foo().bar().expect(456));",
228
+ options: [{
229
+ assertFunctionNames: ['request.foo**.expect']
230
+ }],
231
+ errors: [{
232
+ messageId: 'noAssertions',
233
+ type: _utils.AST_NODE_TYPES.CallExpression
234
+ }]
235
+ }, {
236
+ code: "test('should fail', () => tester.request(123));",
237
+ options: [{
238
+ assertFunctionNames: ['request.*']
239
+ }],
240
+ errors: [{
241
+ messageId: 'noAssertions',
242
+ type: _utils.AST_NODE_TYPES.CallExpression
243
+ }]
244
+ }, {
245
+ code: "test('should fail', () => request(123));",
246
+ options: [{
247
+ assertFunctionNames: ['request.*']
248
+ }],
249
+ errors: [{
250
+ messageId: 'noAssertions',
251
+ type: _utils.AST_NODE_TYPES.CallExpression
252
+ }]
253
+ }, {
254
+ code: "test('should fail', () => request(123));",
255
+ options: [{
256
+ assertFunctionNames: ['request.**']
257
+ }],
258
+ errors: [{
259
+ messageId: 'noAssertions',
260
+ type: _utils.AST_NODE_TYPES.CallExpression
261
+ }]
262
+ }]
263
+ });
264
+ ruleTester.run('expect-expect (aliases)', _expectExpect.default, {
265
+ valid: [{
266
+ code: (0, _dedent.default)`
267
+ import { test } from '@jest/globals';
268
+
269
+ test('should pass', () => {
270
+ expect(true).toBeDefined();
271
+ foo(true).toBe(true);
272
+ });
273
+ `,
274
+ options: [{
275
+ assertFunctionNames: ['expect', 'foo']
276
+ }],
277
+ parserOptions: {
278
+ sourceType: 'module'
279
+ }
280
+ }, {
281
+ code: (0, _dedent.default)`
282
+ import { test as checkThat } from '@jest/globals';
283
+
284
+ checkThat('this passes', () => {
285
+ expect(true).toBeDefined();
286
+ foo(true).toBe(true);
287
+ });
288
+ `,
289
+ options: [{
290
+ assertFunctionNames: ['expect', 'foo']
291
+ }],
292
+ parserOptions: {
293
+ sourceType: 'module'
294
+ }
295
+ }, {
296
+ code: (0, _dedent.default)`
297
+ const { test } = require('@jest/globals');
298
+
299
+ test('verifies chained expect method call', () => {
300
+ tester
301
+ .foo()
302
+ .bar()
303
+ .expect(456);
304
+ });
305
+ `,
306
+ options: [{
307
+ assertFunctionNames: ['tester.foo.bar.expect']
308
+ }],
309
+ parserOptions: {
310
+ sourceType: 'module'
311
+ }
312
+ }],
313
+ invalid: [{
314
+ code: (0, _dedent.default)`
315
+ import { test as checkThat } from '@jest/globals';
316
+
317
+ checkThat('this passes', () => {
318
+ // ...
319
+ });
320
+ `,
321
+ options: [{
322
+ assertFunctionNames: ['expect', 'foo']
323
+ }],
324
+ parserOptions: {
325
+ sourceType: 'module'
326
+ },
327
+ errors: [{
328
+ messageId: 'noAssertions',
329
+ type: _utils.AST_NODE_TYPES.CallExpression
330
+ }]
331
+ }, {
332
+ code: (0, _dedent.default)`
333
+ import { test as checkThat } from '@jest/globals';
334
+
335
+ checkThat.skip('this passes', () => {
336
+ // ...
337
+ });
338
+ `,
339
+ parserOptions: {
340
+ sourceType: 'module'
341
+ },
342
+ errors: [{
343
+ messageId: 'noAssertions',
344
+ type: _utils.AST_NODE_TYPES.CallExpression
345
+ }]
346
+ }]
347
+ });
@@ -0,0 +1,13 @@
1
+ // used by no-throw-literal test case to validate custom error
2
+ export class Error {}
3
+
4
+ // used by unbound-method test case to test imports
5
+ export const console = { log() {} };
6
+
7
+ // used by prefer-reduce-type-parameter to test native vs userland check
8
+ export class Reducable {
9
+ reduce() {}
10
+ }
11
+
12
+ // used by no-implied-eval test function imports
13
+ export class Function {}
File without changes
@@ -0,0 +1 @@
1
+ export type T = number;