eslint-plugin-jest 27.2.2 → 27.3.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 (77) hide show
  1. package/README.md +1 -0
  2. package/docs/rules/no-confusing-set-timeout.md +62 -0
  3. package/lib/rules/expect-expect.js +3 -1
  4. package/lib/rules/no-confusing-set-timeout.js +65 -0
  5. package/lib/rules/no-deprecated-functions.js +2 -2
  6. package/lib/rules/no-test-return-statement.js +9 -3
  7. package/lib/rules/no-untyped-mock-factory.js +3 -1
  8. package/lib/rules/prefer-spy-on.js +6 -2
  9. package/lib/rules/unbound-method.js +1 -1
  10. package/package.json +13 -16
  11. package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
  12. package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
  13. package/lib/rules/__tests__/expect-expect.test.js +0 -347
  14. package/lib/rules/__tests__/fixtures/class.ts +0 -13
  15. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  16. package/lib/rules/__tests__/fixtures/foo.ts +0 -1
  17. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
  18. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
  19. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  20. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
  21. package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
  22. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  23. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  24. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +0 -15
  25. package/lib/rules/__tests__/max-expects.test.js +0 -330
  26. package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
  27. package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
  28. package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
  29. package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
  30. package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
  31. package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
  32. package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
  33. package/lib/rules/__tests__/no-done-callback.test.js +0 -424
  34. package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
  35. package/lib/rules/__tests__/no-export.test.js +0 -107
  36. package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
  37. package/lib/rules/__tests__/no-hooks.test.js +0 -90
  38. package/lib/rules/__tests__/no-identical-title.test.js +0 -270
  39. package/lib/rules/__tests__/no-if.test.js +0 -787
  40. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
  41. package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
  42. package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
  43. package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
  44. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
  45. package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
  46. package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
  47. package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
  48. package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
  49. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
  50. package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
  51. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
  52. package/lib/rules/__tests__/prefer-each.test.js +0 -295
  53. package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
  54. package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
  55. package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
  56. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
  57. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
  58. package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
  59. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
  60. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
  61. package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
  62. package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
  63. package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
  64. package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
  65. package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
  66. package/lib/rules/__tests__/prefer-todo.test.js +0 -78
  67. package/lib/rules/__tests__/require-hook.test.js +0 -403
  68. package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
  69. package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
  70. package/lib/rules/__tests__/test-utils.js +0 -11
  71. package/lib/rules/__tests__/unbound-method.test.js +0 -518
  72. package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
  73. package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
  74. package/lib/rules/__tests__/valid-expect.test.js +0 -894
  75. package/lib/rules/__tests__/valid-title.test.js +0 -1147
  76. package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
  77. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
@@ -1,347 +0,0 @@
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
- });
@@ -1,13 +0,0 @@
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
@@ -1 +0,0 @@
1
- export type T = number;