eslint-plugin-jest 27.2.2 → 27.2.3

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 (69) hide show
  1. package/lib/rules/no-deprecated-functions.js +2 -2
  2. package/package.json +6 -6
  3. package/lib/processors/__tests__/snapshot-processor.test.js +0 -36
  4. package/lib/rules/__tests__/consistent-test-it.test.js +0 -921
  5. package/lib/rules/__tests__/expect-expect.test.js +0 -347
  6. package/lib/rules/__tests__/fixtures/class.ts +0 -13
  7. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  8. package/lib/rules/__tests__/fixtures/foo.ts +0 -1
  9. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +0 -530
  10. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +0 -530
  11. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  12. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +0 -6
  13. package/lib/rules/__tests__/fixtures/tsconfig.json +0 -16
  14. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  15. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  16. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +0 -15
  17. package/lib/rules/__tests__/max-expects.test.js +0 -330
  18. package/lib/rules/__tests__/max-nested-describe.test.js +0 -247
  19. package/lib/rules/__tests__/no-alias-methods.test.js +0 -190
  20. package/lib/rules/__tests__/no-commented-out-tests.test.js +0 -213
  21. package/lib/rules/__tests__/no-conditional-expect.test.js +0 -696
  22. package/lib/rules/__tests__/no-conditional-in-test.test.js +0 -777
  23. package/lib/rules/__tests__/no-deprecated-functions.test.js +0 -119
  24. package/lib/rules/__tests__/no-disabled-tests.test.js +0 -241
  25. package/lib/rules/__tests__/no-done-callback.test.js +0 -424
  26. package/lib/rules/__tests__/no-duplicate-hooks.test.js +0 -469
  27. package/lib/rules/__tests__/no-export.test.js +0 -107
  28. package/lib/rules/__tests__/no-focused-tests.test.js +0 -373
  29. package/lib/rules/__tests__/no-hooks.test.js +0 -90
  30. package/lib/rules/__tests__/no-identical-title.test.js +0 -270
  31. package/lib/rules/__tests__/no-if.test.js +0 -787
  32. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +0 -58
  33. package/lib/rules/__tests__/no-jasmine-globals.test.js +0 -206
  34. package/lib/rules/__tests__/no-large-snapshots.test.js +0 -237
  35. package/lib/rules/__tests__/no-mocks-import.test.js +0 -73
  36. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +0 -103
  37. package/lib/rules/__tests__/no-restricted-matchers.test.js +0 -244
  38. package/lib/rules/__tests__/no-standalone-expect.test.js +0 -230
  39. package/lib/rules/__tests__/no-test-prefixes.test.js +0 -206
  40. package/lib/rules/__tests__/no-test-return-statement.test.js +0 -122
  41. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +0 -149
  42. package/lib/rules/__tests__/prefer-called-with.test.js +0 -40
  43. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +0 -200
  44. package/lib/rules/__tests__/prefer-each.test.js +0 -295
  45. package/lib/rules/__tests__/prefer-equality-matcher.test.js +0 -184
  46. package/lib/rules/__tests__/prefer-expect-assertions.test.js +0 -1437
  47. package/lib/rules/__tests__/prefer-expect-resolves.test.js +0 -96
  48. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +0 -678
  49. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +0 -218
  50. package/lib/rules/__tests__/prefer-lowercase-title.test.js +0 -619
  51. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +0 -360
  52. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +0 -784
  53. package/lib/rules/__tests__/prefer-spy-on.test.js +0 -100
  54. package/lib/rules/__tests__/prefer-strict-equal.test.js +0 -46
  55. package/lib/rules/__tests__/prefer-to-be.test.js +0 -438
  56. package/lib/rules/__tests__/prefer-to-contain.test.js +0 -301
  57. package/lib/rules/__tests__/prefer-to-have-length.test.js +0 -99
  58. package/lib/rules/__tests__/prefer-todo.test.js +0 -78
  59. package/lib/rules/__tests__/require-hook.test.js +0 -403
  60. package/lib/rules/__tests__/require-to-throw-message.test.js +0 -108
  61. package/lib/rules/__tests__/require-top-level-describe.test.js +0 -236
  62. package/lib/rules/__tests__/test-utils.js +0 -11
  63. package/lib/rules/__tests__/unbound-method.test.js +0 -518
  64. package/lib/rules/__tests__/valid-describe-callback.test.js +0 -305
  65. package/lib/rules/__tests__/valid-expect-in-promise.test.js +0 -1583
  66. package/lib/rules/__tests__/valid-expect.test.js +0 -894
  67. package/lib/rules/__tests__/valid-title.test.js +0 -1147
  68. package/lib/rules/utils/__tests__/detectJestVersion.test.js +0 -221
  69. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +0 -809
@@ -1,696 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("@typescript-eslint/utils");
4
- var _dedent = _interopRequireDefault(require("dedent"));
5
- var _noConditionalExpect = _interopRequireDefault(require("../no-conditional-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: 2019
12
- }
13
- });
14
- ruleTester.run('common tests', _noConditionalExpect.default, {
15
- valid: [`
16
- it('foo', () => {
17
- expect(1).toBe(2);
18
- });
19
- `, `
20
- it('foo', () => {
21
- expect(!true).toBe(false);
22
- });
23
- `],
24
- invalid: []
25
- });
26
- ruleTester.run('logical conditions', _noConditionalExpect.default, {
27
- valid: [`
28
- it('foo', () => {
29
- process.env.FAIL && setNum(1);
30
-
31
- expect(num).toBe(2);
32
- });
33
- `, `
34
- function getValue() {
35
- let num = 2;
36
-
37
- process.env.FAIL && setNum(1);
38
-
39
- return num;
40
- }
41
-
42
- it('foo', () => {
43
- expect(getValue()).toBe(2);
44
- });
45
- `, `
46
- it('foo', () => {
47
- process.env.FAIL || setNum(1);
48
-
49
- expect(num).toBe(2);
50
- });
51
- `, `
52
- function getValue() {
53
- let num = 2;
54
-
55
- process.env.FAIL || setNum(1);
56
-
57
- return num;
58
- }
59
-
60
- it('foo', () => {
61
- expect(getValue()).toBe(2);
62
- });
63
- `],
64
- invalid: [{
65
- code: `
66
- it('foo', () => {
67
- something && expect(something).toHaveBeenCalled();
68
- })
69
- `,
70
- errors: [{
71
- messageId: 'conditionalExpect'
72
- }]
73
- }, {
74
- code: `
75
- it('foo', () => {
76
- a || b && expect(something).toHaveBeenCalled();
77
- })
78
- `,
79
- errors: [{
80
- messageId: 'conditionalExpect'
81
- }]
82
- }, {
83
- code: `
84
- it('foo', () => {
85
- (a || b) && expect(something).toHaveBeenCalled();
86
- })
87
- `,
88
- errors: [{
89
- messageId: 'conditionalExpect'
90
- }]
91
- }, {
92
- code: `
93
- it('foo', () => {
94
- a || (b && expect(something).toHaveBeenCalled());
95
- })
96
- `,
97
- errors: [{
98
- messageId: 'conditionalExpect'
99
- }]
100
- }, {
101
- code: `
102
- it('foo', () => {
103
- a && b && expect(something).toHaveBeenCalled();
104
- })
105
- `,
106
- errors: [{
107
- messageId: 'conditionalExpect'
108
- }]
109
- }, {
110
- code: `
111
- it('foo', () => {
112
- a && b || expect(something).toHaveBeenCalled();
113
- })
114
- `,
115
- errors: [{
116
- messageId: 'conditionalExpect'
117
- }]
118
- }, {
119
- code: `
120
- it('foo', () => {
121
- (a && b) || expect(something).toHaveBeenCalled();
122
- })
123
- `,
124
- errors: [{
125
- messageId: 'conditionalExpect'
126
- }]
127
- }, {
128
- code: `
129
- function getValue() {
130
- something && expect(something).toHaveBeenCalled();
131
- }
132
-
133
- it('foo', getValue);
134
- `,
135
- errors: [{
136
- messageId: 'conditionalExpect'
137
- }]
138
- }, {
139
- code: `
140
- it('foo', () => {
141
- something || expect(something).toHaveBeenCalled();
142
- })
143
- `,
144
- errors: [{
145
- messageId: 'conditionalExpect'
146
- }]
147
- }, {
148
- code: `
149
- it.each\`\`('foo', () => {
150
- something || expect(something).toHaveBeenCalled();
151
- })
152
- `,
153
- errors: [{
154
- messageId: 'conditionalExpect'
155
- }]
156
- }, {
157
- code: `
158
- it.each()('foo', () => {
159
- something || expect(something).toHaveBeenCalled();
160
- })
161
- `,
162
- errors: [{
163
- messageId: 'conditionalExpect'
164
- }]
165
- }, {
166
- code: `
167
- function getValue() {
168
- something || expect(something).toHaveBeenCalled();
169
- }
170
-
171
- it('foo', getValue);
172
- `,
173
- errors: [{
174
- messageId: 'conditionalExpect'
175
- }]
176
- }]
177
- });
178
- ruleTester.run('conditional conditions', _noConditionalExpect.default, {
179
- valid: [`
180
- it('foo', () => {
181
- const num = process.env.FAIL ? 1 : 2;
182
-
183
- expect(num).toBe(2);
184
- });
185
- `, `
186
- function getValue() {
187
- return process.env.FAIL ? 1 : 2
188
- }
189
-
190
- it('foo', () => {
191
- expect(getValue()).toBe(2);
192
- });
193
- `],
194
- invalid: [{
195
- code: `
196
- it('foo', () => {
197
- something ? expect(something).toHaveBeenCalled() : noop();
198
- })
199
- `,
200
- errors: [{
201
- messageId: 'conditionalExpect'
202
- }]
203
- }, {
204
- code: `
205
- function getValue() {
206
- something ? expect(something).toHaveBeenCalled() : noop();
207
- }
208
-
209
- it('foo', getValue);
210
- `,
211
- errors: [{
212
- messageId: 'conditionalExpect'
213
- }]
214
- }, {
215
- code: `
216
- it('foo', () => {
217
- something ? noop() : expect(something).toHaveBeenCalled();
218
- })
219
- `,
220
- errors: [{
221
- messageId: 'conditionalExpect'
222
- }]
223
- }, {
224
- code: `
225
- it.each\`\`('foo', () => {
226
- something ? noop() : expect(something).toHaveBeenCalled();
227
- })
228
- `,
229
- errors: [{
230
- messageId: 'conditionalExpect'
231
- }]
232
- }, {
233
- code: `
234
- it.each()('foo', () => {
235
- something ? noop() : expect(something).toHaveBeenCalled();
236
- })
237
- `,
238
- errors: [{
239
- messageId: 'conditionalExpect'
240
- }]
241
- }, {
242
- code: `
243
- function getValue() {
244
- something ? noop() : expect(something).toHaveBeenCalled();
245
- }
246
-
247
- it('foo', getValue);
248
- `,
249
- errors: [{
250
- messageId: 'conditionalExpect'
251
- }]
252
- }]
253
- });
254
- ruleTester.run('switch conditions', _noConditionalExpect.default, {
255
- valid: [`
256
- it('foo', () => {
257
- let num;
258
-
259
- switch(process.env.FAIL) {
260
- case true:
261
- num = 1;
262
- break;
263
- case false:
264
- num = 2;
265
- break;
266
- }
267
-
268
- expect(num).toBe(2);
269
- });
270
- `, `
271
- function getValue() {
272
- switch(process.env.FAIL) {
273
- case true:
274
- return 1;
275
- case false:
276
- return 2;
277
- }
278
- }
279
-
280
- it('foo', () => {
281
- expect(getValue()).toBe(2);
282
- });
283
- `],
284
- invalid: [{
285
- code: `
286
- it('foo', () => {
287
- switch(something) {
288
- case 'value':
289
- break;
290
- default:
291
- expect(something).toHaveBeenCalled();
292
- }
293
- })
294
- `,
295
- errors: [{
296
- messageId: 'conditionalExpect'
297
- }]
298
- }, {
299
- code: `
300
- it('foo', () => {
301
- switch(something) {
302
- case 'value':
303
- expect(something).toHaveBeenCalled();
304
- default:
305
- break;
306
- }
307
- })
308
- `,
309
- errors: [{
310
- messageId: 'conditionalExpect'
311
- }]
312
- }, {
313
- code: `
314
- it.each\`\`('foo', () => {
315
- switch(something) {
316
- case 'value':
317
- expect(something).toHaveBeenCalled();
318
- default:
319
- break;
320
- }
321
- })
322
- `,
323
- errors: [{
324
- messageId: 'conditionalExpect'
325
- }]
326
- }, {
327
- code: `
328
- it.each()('foo', () => {
329
- switch(something) {
330
- case 'value':
331
- expect(something).toHaveBeenCalled();
332
- default:
333
- break;
334
- }
335
- })
336
- `,
337
- errors: [{
338
- messageId: 'conditionalExpect'
339
- }]
340
- }, {
341
- code: `
342
- function getValue() {
343
- switch(something) {
344
- case 'value':
345
- break;
346
- default:
347
- expect(something).toHaveBeenCalled();
348
- }
349
- }
350
-
351
- it('foo', getValue);
352
- `,
353
- errors: [{
354
- messageId: 'conditionalExpect'
355
- }]
356
- }]
357
- });
358
- ruleTester.run('if conditions', _noConditionalExpect.default, {
359
- valid: [`
360
- it('foo', () => {
361
- let num = 2;
362
-
363
- if(process.env.FAIL) {
364
- num = 1;
365
- }
366
-
367
- expect(num).toBe(2);
368
- });
369
- `, `
370
- function getValue() {
371
- if(process.env.FAIL) {
372
- return 1;
373
- }
374
-
375
- return 2;
376
- }
377
-
378
- it('foo', () => {
379
- expect(getValue()).toBe(2);
380
- });
381
- `],
382
- invalid: [{
383
- code: `
384
- it('foo', () => {
385
- if(doSomething) {
386
- expect(something).toHaveBeenCalled();
387
- }
388
- })
389
- `,
390
- errors: [{
391
- messageId: 'conditionalExpect'
392
- }]
393
- }, {
394
- code: `
395
- it('foo', () => {
396
- if(!doSomething) {
397
- // do nothing
398
- } else {
399
- expect(something).toHaveBeenCalled();
400
- }
401
- })
402
- `,
403
- errors: [{
404
- messageId: 'conditionalExpect'
405
- }]
406
- }, {
407
- code: `
408
- it.each\`\`('foo', () => {
409
- if(!doSomething) {
410
- // do nothing
411
- } else {
412
- expect(something).toHaveBeenCalled();
413
- }
414
- })
415
- `,
416
- errors: [{
417
- messageId: 'conditionalExpect'
418
- }]
419
- }, {
420
- code: `
421
- it.each()('foo', () => {
422
- if(!doSomething) {
423
- // do nothing
424
- } else {
425
- expect(something).toHaveBeenCalled();
426
- }
427
- })
428
- `,
429
- errors: [{
430
- messageId: 'conditionalExpect'
431
- }]
432
- }, {
433
- code: `
434
- function getValue() {
435
- if(doSomething) {
436
- expect(something).toHaveBeenCalled();
437
- }
438
- }
439
-
440
- it('foo', getValue);
441
- `,
442
- errors: [{
443
- messageId: 'conditionalExpect'
444
- }]
445
- }, {
446
- code: `
447
- function getValue() {
448
- if(!doSomething) {
449
- // do nothing
450
- } else {
451
- expect(something).toHaveBeenCalled();
452
- }
453
- }
454
-
455
- it('foo', getValue);
456
- `,
457
- errors: [{
458
- messageId: 'conditionalExpect'
459
- }]
460
- }]
461
- });
462
- ruleTester.run('catch conditions', _noConditionalExpect.default, {
463
- valid: [`
464
- it('foo', () => {
465
- try {
466
- // do something
467
- } catch {
468
- // ignore errors
469
- } finally {
470
- expect(something).toHaveBeenCalled();
471
- }
472
- });
473
- `, `
474
- it('foo', () => {
475
- try {
476
- // do something
477
- } catch {
478
- // ignore errors
479
- }
480
-
481
- expect(something).toHaveBeenCalled();
482
- });
483
- `, `
484
- function getValue() {
485
- try {
486
- // do something
487
- } catch {
488
- // ignore errors
489
- } finally {
490
- expect(something).toHaveBeenCalled();
491
- }
492
- }
493
-
494
- it('foo', getValue);
495
- `, `
496
- function getValue() {
497
- try {
498
- process.env.FAIL.toString();
499
-
500
- return 1;
501
- } catch {
502
- return 2;
503
- }
504
- }
505
-
506
- it('foo', () => {
507
- expect(getValue()).toBe(2);
508
- });
509
- `],
510
- invalid: [{
511
- code: `
512
- it('foo', () => {
513
- try {
514
-
515
- } catch (err) {
516
- expect(err).toMatch('Error');
517
- }
518
- })
519
- `,
520
- errors: [{
521
- messageId: 'conditionalExpect'
522
- }]
523
- }, {
524
- code: `
525
- it.each\`\`('foo', () => {
526
- try {
527
-
528
- } catch (err) {
529
- expect(err).toMatch('Error');
530
- }
531
- })
532
- `,
533
- errors: [{
534
- messageId: 'conditionalExpect'
535
- }]
536
- }, {
537
- code: `
538
- it.each()('foo', () => {
539
- try {
540
-
541
- } catch (err) {
542
- expect(err).toMatch('Error');
543
- }
544
- })
545
- `,
546
- errors: [{
547
- messageId: 'conditionalExpect'
548
- }]
549
- }, {
550
- code: `
551
- it.skip.each\`\`('foo', () => {
552
- try {
553
-
554
- } catch (err) {
555
- expect(err).toMatch('Error');
556
- }
557
- })
558
- `,
559
- errors: [{
560
- messageId: 'conditionalExpect'
561
- }]
562
- }, {
563
- code: `
564
- it.skip.each()('foo', () => {
565
- try {
566
-
567
- } catch (err) {
568
- expect(err).toMatch('Error');
569
- }
570
- })
571
- `,
572
- errors: [{
573
- messageId: 'conditionalExpect'
574
- }]
575
- }, {
576
- code: `
577
- function getValue() {
578
- try {
579
- // do something
580
- } catch {
581
- expect(something).toHaveBeenCalled();
582
- }
583
- }
584
-
585
- it('foo', getValue);
586
- `,
587
- errors: [{
588
- messageId: 'conditionalExpect'
589
- }]
590
- }]
591
- });
592
- ruleTester.run('promises', _noConditionalExpect.default, {
593
- valid: [`
594
- it('works', async () => {
595
- try {
596
- await Promise.resolve().then(() => {
597
- throw new Error('oh noes!');
598
- });
599
- } catch {
600
- // ignore errors
601
- } finally {
602
- expect(something).toHaveBeenCalled();
603
- }
604
- });
605
- `, `
606
- it('works', async () => {
607
- await doSomething().catch(error => error);
608
-
609
- expect(error).toBeInstanceOf(Error);
610
- });
611
- `, `
612
- it('works', async () => {
613
- try {
614
- await Promise.resolve().then(() => {
615
- throw new Error('oh noes!');
616
- });
617
- } catch {
618
- // ignore errors
619
- }
620
-
621
- expect(something).toHaveBeenCalled();
622
- });
623
- `],
624
- invalid: [{
625
- code: (0, _dedent.default)`
626
- it('works', async () => {
627
- await Promise.resolve()
628
- .then(() => { throw new Error('oh noes!'); })
629
- .catch(error => expect(error).toBeInstanceOf(Error));
630
- });
631
- `,
632
- errors: [{
633
- messageId: 'conditionalExpect'
634
- }]
635
- }, {
636
- code: (0, _dedent.default)`
637
- it('works', async () => {
638
- await Promise.resolve()
639
- .then(() => { throw new Error('oh noes!'); })
640
- .catch(error => expect(error).toBeInstanceOf(Error))
641
- .then(() => { throw new Error('oh noes!'); })
642
- .catch(error => expect(error).toBeInstanceOf(Error))
643
- .then(() => { throw new Error('oh noes!'); })
644
- .catch(error => expect(error).toBeInstanceOf(Error));
645
- });
646
- `,
647
- errors: [{
648
- messageId: 'conditionalExpect'
649
- }]
650
- }, {
651
- code: (0, _dedent.default)`
652
- it('works', async () => {
653
- await Promise.resolve()
654
- .catch(error => expect(error).toBeInstanceOf(Error))
655
- .catch(error => expect(error).toBeInstanceOf(Error))
656
- .catch(error => expect(error).toBeInstanceOf(Error));
657
- });
658
- `,
659
- errors: [{
660
- messageId: 'conditionalExpect'
661
- }]
662
- }, {
663
- code: (0, _dedent.default)`
664
- it('works', async () => {
665
- await Promise.resolve()
666
- .catch(error => expect(error).toBeInstanceOf(Error))
667
- .then(() => { throw new Error('oh noes!'); })
668
- .then(() => { throw new Error('oh noes!'); })
669
- .then(() => { throw new Error('oh noes!'); });
670
- });
671
- `,
672
- errors: [{
673
- messageId: 'conditionalExpect'
674
- }]
675
- }, {
676
- code: (0, _dedent.default)`
677
- it('works', async () => {
678
- await somePromise
679
- .then(() => { throw new Error('oh noes!'); })
680
- .catch(error => expect(error).toBeInstanceOf(Error));
681
- });
682
- `,
683
- errors: [{
684
- messageId: 'conditionalExpect'
685
- }]
686
- }, {
687
- code: (0, _dedent.default)`
688
- it('works', async () => {
689
- await somePromise.catch(error => expect(error).toBeInstanceOf(Error));
690
- });
691
- `,
692
- errors: [{
693
- messageId: 'conditionalExpect'
694
- }]
695
- }]
696
- });