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,784 @@
1
+ "use strict";
2
+
3
+ var _utils = require("@typescript-eslint/utils");
4
+ var _dedent = _interopRequireDefault(require("dedent"));
5
+ var _preferSnapshotHint = _interopRequireDefault(require("../prefer-snapshot-hint"));
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('prefer-snapshot-hint (always)', _preferSnapshotHint.default, {
15
+ valid: [{
16
+ code: 'expect(something).toStrictEqual(somethingElse);',
17
+ options: ['always']
18
+ }, {
19
+ code: "a().toEqual('b')",
20
+ options: ['always']
21
+ }, {
22
+ code: 'expect(a);',
23
+ options: ['always']
24
+ }, {
25
+ code: 'expect(1).toMatchSnapshot({}, "my snapshot");',
26
+ options: ['always']
27
+ }, {
28
+ code: 'expect(1).toMatchSnapshot("my snapshot");',
29
+ options: ['always']
30
+ }, {
31
+ code: 'expect(1).toMatchSnapshot(`my snapshot`);',
32
+ options: ['always']
33
+ }, {
34
+ code: (0, _dedent.default)`
35
+ const x = {};
36
+ expect(1).toMatchSnapshot(x, "my snapshot");
37
+ `,
38
+ options: ['always']
39
+ }, {
40
+ code: (0, _dedent.default)`
41
+ const x = "snapshot";
42
+ expect(1).toMatchSnapshot(\`my $\{x}\`);
43
+ `,
44
+ options: ['always']
45
+ }, {
46
+ code: 'expect(1).toThrowErrorMatchingSnapshot("my snapshot");',
47
+ options: ['always']
48
+ }, {
49
+ code: 'expect(1).toMatchInlineSnapshot();',
50
+ options: ['always']
51
+ }, {
52
+ code: 'expect(1).toThrowErrorMatchingInlineSnapshot();',
53
+ options: ['always']
54
+ }],
55
+ invalid: [{
56
+ code: 'expect(1).toMatchSnapshot();',
57
+ options: ['always'],
58
+ errors: [{
59
+ messageId: 'missingHint',
60
+ column: 11,
61
+ line: 1
62
+ }]
63
+ }, {
64
+ code: 'expect(1).toMatchSnapshot({});',
65
+ options: ['always'],
66
+ errors: [{
67
+ messageId: 'missingHint',
68
+ column: 11,
69
+ line: 1
70
+ }]
71
+ }, {
72
+ code: (0, _dedent.default)`
73
+ const x = "we can't know if this is a string or not";
74
+ expect(1).toMatchSnapshot(x);
75
+ `,
76
+ options: ['always'],
77
+ errors: [{
78
+ messageId: 'missingHint',
79
+ column: 11,
80
+ line: 2
81
+ }]
82
+ }, {
83
+ code: 'expect(1).toThrowErrorMatchingSnapshot();',
84
+ options: ['always'],
85
+ errors: [{
86
+ messageId: 'missingHint',
87
+ column: 11,
88
+ line: 1
89
+ }]
90
+ }, {
91
+ code: (0, _dedent.default)`
92
+ it('is true', () => {
93
+ expect(1).toMatchSnapshot();
94
+ });
95
+ `,
96
+ options: ['always'],
97
+ errors: [{
98
+ messageId: 'missingHint',
99
+ column: 13,
100
+ line: 2
101
+ }]
102
+ }, {
103
+ code: (0, _dedent.default)`
104
+ it('is true', () => {
105
+ expect(1).toMatchSnapshot();
106
+ expect(2).toMatchSnapshot();
107
+ });
108
+ `,
109
+ options: ['always'],
110
+ errors: [{
111
+ messageId: 'missingHint',
112
+ column: 13,
113
+ line: 2
114
+ }, {
115
+ messageId: 'missingHint',
116
+ column: 13,
117
+ line: 3
118
+ }]
119
+ }, {
120
+ code: (0, _dedent.default)`
121
+ it('is true', () => {
122
+ expect(1).toMatchSnapshot();
123
+ expect(2).toThrowErrorMatchingSnapshot("my error");
124
+ });
125
+ `,
126
+ options: ['always'],
127
+ errors: [{
128
+ messageId: 'missingHint',
129
+ column: 13,
130
+ line: 2
131
+ }]
132
+ }, {
133
+ code: (0, _dedent.default)`
134
+ const expectSnapshot = value => {
135
+ expect(value).toMatchSnapshot();
136
+ };
137
+ `,
138
+ options: ['always'],
139
+ errors: [{
140
+ messageId: 'missingHint',
141
+ column: 17,
142
+ line: 2
143
+ }]
144
+ }, {
145
+ code: (0, _dedent.default)`
146
+ const expectSnapshot = value => {
147
+ expect(value).toThrowErrorMatchingSnapshot();
148
+ };
149
+ `,
150
+ options: ['always'],
151
+ errors: [{
152
+ messageId: 'missingHint',
153
+ column: 17,
154
+ line: 2
155
+ }]
156
+ }, {
157
+ code: (0, _dedent.default)`
158
+ it('is true', () => {
159
+ { expect(1).toMatchSnapshot(); }
160
+ });
161
+ `,
162
+ options: ['always'],
163
+ errors: [{
164
+ messageId: 'missingHint',
165
+ column: 15,
166
+ line: 2
167
+ }]
168
+ }]
169
+ });
170
+ ruleTester.run('prefer-snapshot-hint (multi)', _preferSnapshotHint.default, {
171
+ valid: [{
172
+ code: 'expect(something).toStrictEqual(somethingElse);',
173
+ options: ['multi']
174
+ }, {
175
+ code: "a().toEqual('b')",
176
+ options: ['multi']
177
+ }, {
178
+ code: 'expect(a);',
179
+ options: ['multi']
180
+ }, {
181
+ code: 'expect(1).toMatchSnapshot({}, "my snapshot");',
182
+ options: ['multi']
183
+ }, {
184
+ code: 'expect(1).toThrowErrorMatchingSnapshot("my snapshot");',
185
+ options: ['multi']
186
+ }, {
187
+ code: 'expect(1).toMatchSnapshot({});',
188
+ options: ['multi']
189
+ }, {
190
+ code: 'expect(1).toThrowErrorMatchingSnapshot();',
191
+ options: ['multi']
192
+ }, {
193
+ code: (0, _dedent.default)`
194
+ it('is true', () => {
195
+ expect(1).toMatchSnapshot();
196
+ });
197
+ `,
198
+ options: ['multi']
199
+ }, {
200
+ code: (0, _dedent.default)`
201
+ it('is true', () => {
202
+ expect(1).toMatchSnapshot(undefined, 'my first snapshot');
203
+ });
204
+ `,
205
+ options: ['multi']
206
+ }, {
207
+ code: (0, _dedent.default)`
208
+ describe('my tests', () => {
209
+ it('is true', () => {
210
+ expect(1).toMatchSnapshot('this is a hint, all by itself');
211
+ });
212
+
213
+ it('is false', () => {
214
+ expect(2).toMatchSnapshot('this is a hint');
215
+ expect(2).toMatchSnapshot('and so is this');
216
+ });
217
+ });
218
+ `,
219
+ options: ['multi']
220
+ }, {
221
+ code: (0, _dedent.default)`
222
+ it('is true', () => {
223
+ expect(1).toMatchSnapshot();
224
+ });
225
+
226
+ it('is false', () => {
227
+ expect(2).toMatchSnapshot('this is a hint');
228
+ expect(2).toMatchSnapshot('and so is this');
229
+ });
230
+ `,
231
+ options: ['multi']
232
+ }, {
233
+ code: (0, _dedent.default)`
234
+ it('is true', () => {
235
+ expect(1).toMatchSnapshot();
236
+ });
237
+
238
+ it('is false', () => {
239
+ expect(2).toThrowErrorMatchingSnapshot();
240
+ });
241
+ `,
242
+ options: ['multi']
243
+ }, {
244
+ code: (0, _dedent.default)`
245
+ it('is true', () => {
246
+ expect(1).toStrictEqual(1);
247
+ expect(1).toStrictEqual(2);
248
+ expect(1).toMatchSnapshot();
249
+ });
250
+
251
+ it('is false', () => {
252
+ expect(1).toStrictEqual(1);
253
+ expect(1).toStrictEqual(2);
254
+ expect(2).toThrowErrorMatchingSnapshot();
255
+ });
256
+ `,
257
+ options: ['multi']
258
+ }, {
259
+ code: (0, _dedent.default)`
260
+ it('is true', () => {
261
+ expect(1).toMatchInlineSnapshot();
262
+ });
263
+
264
+ it('is false', () => {
265
+ expect(1).toMatchInlineSnapshot();
266
+ expect(1).toMatchInlineSnapshot();
267
+ expect(1).toThrowErrorMatchingInlineSnapshot();
268
+ });
269
+ `,
270
+ options: ['multi']
271
+ }, {
272
+ code: (0, _dedent.default)`
273
+ it('is true', () => {
274
+ expect(1).toMatchSnapshot();
275
+ });
276
+
277
+ it('is false', () => {
278
+ expect(1).toMatchSnapshot();
279
+ });
280
+ `,
281
+ options: ['multi']
282
+ }, {
283
+ code: (0, _dedent.default)`
284
+ import { it as itIs } from '@jest/globals';
285
+
286
+ it('is true', () => {
287
+ expect(1).toMatchSnapshot();
288
+ });
289
+
290
+ itIs('false', () => {
291
+ expect(1).toMatchSnapshot();
292
+ });
293
+ `,
294
+ options: ['multi'],
295
+ parserOptions: {
296
+ sourceType: 'module'
297
+ }
298
+ }, {
299
+ code: (0, _dedent.default)`
300
+ const myReusableTestBody = (value, snapshotHint) => {
301
+ const innerFn = anotherValue => {
302
+ expect(anotherValue).toMatchSnapshot();
303
+
304
+ expect(value).toBe(1);
305
+ };
306
+
307
+ expect(value).toBe(1);
308
+ };
309
+
310
+ it('my test', () => {
311
+ expect(1).toMatchSnapshot();
312
+ });
313
+ `,
314
+ options: ['multi']
315
+ }, {
316
+ code: (0, _dedent.default)`
317
+ const myReusableTestBody = (value, snapshotHint) => {
318
+ const innerFn = anotherValue => {
319
+ expect(value).toBe(1);
320
+ };
321
+
322
+ expect(value).toBe(1);
323
+ expect(anotherValue).toMatchSnapshot();
324
+ };
325
+
326
+ it('my test', () => {
327
+ expect(1).toMatchSnapshot();
328
+ });
329
+ `,
330
+ options: ['multi']
331
+ }, {
332
+ code: (0, _dedent.default)`
333
+ const myReusableTestBody = (value, snapshotHint) => {
334
+ const innerFn = anotherValue => {
335
+ expect(anotherValue).toMatchSnapshot();
336
+
337
+ expect(value).toBe(1);
338
+ };
339
+
340
+ expect(value).toBe(1);
341
+ };
342
+
343
+ expect(1).toMatchSnapshot();
344
+ `,
345
+ options: ['multi']
346
+ }],
347
+ invalid: [{
348
+ code: (0, _dedent.default)`
349
+ it('is true', () => {
350
+ expect(1).toMatchSnapshot();
351
+ expect(2).toMatchSnapshot();
352
+ });
353
+ `,
354
+ options: ['multi'],
355
+ errors: [{
356
+ messageId: 'missingHint',
357
+ column: 13,
358
+ line: 2
359
+ }, {
360
+ messageId: 'missingHint',
361
+ column: 13,
362
+ line: 3
363
+ }]
364
+ }, {
365
+ code: (0, _dedent.default)`
366
+ it('is true', () => {
367
+ expect(1).toMatchSnapshot();
368
+ expect(2).toThrowErrorMatchingSnapshot();
369
+ });
370
+ `,
371
+ options: ['multi'],
372
+ errors: [{
373
+ messageId: 'missingHint',
374
+ column: 13,
375
+ line: 2
376
+ }, {
377
+ messageId: 'missingHint',
378
+ column: 13,
379
+ line: 3
380
+ }]
381
+ }, {
382
+ code: (0, _dedent.default)`
383
+ it('is true', () => {
384
+ expect(1).toThrowErrorMatchingSnapshot();
385
+ expect(2).toMatchSnapshot();
386
+ });
387
+ `,
388
+ options: ['multi'],
389
+ errors: [{
390
+ messageId: 'missingHint',
391
+ column: 13,
392
+ line: 2
393
+ }, {
394
+ messageId: 'missingHint',
395
+ column: 13,
396
+ line: 3
397
+ }]
398
+ }, {
399
+ code: (0, _dedent.default)`
400
+ it('is true', () => {
401
+ expect(1).toMatchSnapshot({});
402
+ expect(2).toMatchSnapshot({});
403
+ });
404
+ `,
405
+ options: ['multi'],
406
+ errors: [{
407
+ messageId: 'missingHint',
408
+ column: 13,
409
+ line: 2
410
+ }, {
411
+ messageId: 'missingHint',
412
+ column: 13,
413
+ line: 3
414
+ }]
415
+ }, {
416
+ code: (0, _dedent.default)`
417
+ it('is true', () => {
418
+ expect(1).toMatchSnapshot({});
419
+ {
420
+ expect(2).toMatchSnapshot({});
421
+ }
422
+ });
423
+ `,
424
+ options: ['multi'],
425
+ errors: [{
426
+ messageId: 'missingHint',
427
+ column: 13,
428
+ line: 2
429
+ }, {
430
+ messageId: 'missingHint',
431
+ column: 15,
432
+ line: 4
433
+ }]
434
+ }, {
435
+ code: (0, _dedent.default)`
436
+ it('is true', () => {
437
+ { expect(1).toMatchSnapshot(); }
438
+ { expect(2).toMatchSnapshot(); }
439
+ });
440
+ `,
441
+ options: ['multi'],
442
+ errors: [{
443
+ messageId: 'missingHint',
444
+ column: 15,
445
+ line: 2
446
+ }, {
447
+ messageId: 'missingHint',
448
+ column: 15,
449
+ line: 3
450
+ }]
451
+ }, {
452
+ code: (0, _dedent.default)`
453
+ it('is true', () => {
454
+ expect(1).toMatchSnapshot();
455
+ expect(2).toMatchSnapshot(undefined, 'my second snapshot');
456
+ });
457
+ `,
458
+ options: ['multi'],
459
+ errors: [{
460
+ messageId: 'missingHint',
461
+ column: 13,
462
+ line: 2
463
+ }]
464
+ }, {
465
+ code: (0, _dedent.default)`
466
+ it('is true', () => {
467
+ expect(1).toMatchSnapshot({});
468
+ expect(2).toMatchSnapshot(undefined, 'my second snapshot');
469
+ });
470
+ `,
471
+ options: ['multi'],
472
+ errors: [{
473
+ messageId: 'missingHint',
474
+ column: 13,
475
+ line: 2
476
+ }]
477
+ }, {
478
+ code: (0, _dedent.default)`
479
+ it('is true', () => {
480
+ expect(1).toMatchSnapshot({}, 'my first snapshot');
481
+ expect(2).toMatchSnapshot(undefined);
482
+ });
483
+ `,
484
+ options: ['multi'],
485
+ errors: [{
486
+ messageId: 'missingHint',
487
+ column: 13,
488
+ line: 3
489
+ }]
490
+ }, {
491
+ code: (0, _dedent.default)`
492
+ it('is true', () => {
493
+ expect(1).toMatchSnapshot({}, 'my first snapshot');
494
+ expect(2).toMatchSnapshot(undefined);
495
+ expect(2).toMatchSnapshot();
496
+ });
497
+ `,
498
+ options: ['multi'],
499
+ errors: [{
500
+ messageId: 'missingHint',
501
+ column: 13,
502
+ line: 3
503
+ }, {
504
+ messageId: 'missingHint',
505
+ column: 13,
506
+ line: 4
507
+ }]
508
+ }, {
509
+ code: (0, _dedent.default)`
510
+ it('is true', () => {
511
+ expect(2).toMatchSnapshot();
512
+ expect(1).toMatchSnapshot({}, 'my second snapshot');
513
+ expect(2).toMatchSnapshot();
514
+ });
515
+ `,
516
+ options: ['multi'],
517
+ errors: [{
518
+ messageId: 'missingHint',
519
+ column: 13,
520
+ line: 2
521
+ }, {
522
+ messageId: 'missingHint',
523
+ column: 13,
524
+ line: 4
525
+ }]
526
+ }, {
527
+ code: (0, _dedent.default)`
528
+ it('is true', () => {
529
+ expect(2).toMatchSnapshot(undefined);
530
+ expect(2).toMatchSnapshot();
531
+ expect(1).toMatchSnapshot(null, 'my third snapshot');
532
+ });
533
+ `,
534
+ options: ['multi'],
535
+ errors: [{
536
+ messageId: 'missingHint',
537
+ column: 13,
538
+ line: 2
539
+ }, {
540
+ messageId: 'missingHint',
541
+ column: 13,
542
+ line: 3
543
+ }]
544
+ }, {
545
+ code: (0, _dedent.default)`
546
+ describe('my tests', () => {
547
+ it('is true', () => {
548
+ expect(1).toMatchSnapshot();
549
+ });
550
+
551
+ it('is false', () => {
552
+ expect(2).toMatchSnapshot();
553
+ expect(2).toMatchSnapshot();
554
+ });
555
+ });
556
+ `,
557
+ options: ['multi'],
558
+ errors: [{
559
+ messageId: 'missingHint',
560
+ column: 15,
561
+ line: 7
562
+ }, {
563
+ messageId: 'missingHint',
564
+ column: 15,
565
+ line: 8
566
+ }]
567
+ }, {
568
+ code: (0, _dedent.default)`
569
+ describe('my tests', () => {
570
+ it('is true', () => {
571
+ expect(1).toMatchSnapshot();
572
+ });
573
+
574
+ it('is false', () => {
575
+ expect(2).toMatchSnapshot();
576
+ expect(2).toMatchSnapshot('hello world');
577
+ });
578
+ });
579
+ `,
580
+ options: ['multi'],
581
+ errors: [{
582
+ messageId: 'missingHint',
583
+ column: 15,
584
+ line: 7
585
+ }]
586
+ }, {
587
+ code: (0, _dedent.default)`
588
+ describe('my tests', () => {
589
+ describe('more tests', () => {
590
+ it('is true', () => {
591
+ expect(1).toMatchSnapshot();
592
+ });
593
+ });
594
+
595
+ it('is false', () => {
596
+ expect(2).toMatchSnapshot();
597
+ expect(2).toMatchSnapshot('hello world');
598
+ });
599
+ });
600
+ `,
601
+ options: ['multi'],
602
+ errors: [{
603
+ messageId: 'missingHint',
604
+ column: 15,
605
+ line: 9
606
+ }]
607
+ }, {
608
+ code: (0, _dedent.default)`
609
+ describe('my tests', () => {
610
+ it('is true', () => {
611
+ expect(1).toMatchSnapshot();
612
+ });
613
+
614
+ describe('more tests', () => {
615
+ it('is false', () => {
616
+ expect(2).toMatchSnapshot();
617
+ expect(2).toMatchSnapshot('hello world');
618
+ });
619
+ });
620
+ });
621
+ `,
622
+ options: ['multi'],
623
+ errors: [{
624
+ messageId: 'missingHint',
625
+ column: 17,
626
+ line: 8
627
+ }]
628
+ }, {
629
+ code: (0, _dedent.default)`
630
+ import { describe as context, it as itIs } from '@jest/globals';
631
+
632
+ describe('my tests', () => {
633
+ it('is true', () => {
634
+ expect(1).toMatchSnapshot();
635
+ });
636
+
637
+ context('more tests', () => {
638
+ itIs('false', () => {
639
+ expect(2).toMatchSnapshot();
640
+ expect(2).toMatchSnapshot('hello world');
641
+ });
642
+ });
643
+ });
644
+ `,
645
+ options: ['multi'],
646
+ parserOptions: {
647
+ sourceType: 'module'
648
+ },
649
+ errors: [{
650
+ messageId: 'missingHint',
651
+ column: 17,
652
+ line: 10
653
+ }]
654
+ }, {
655
+ code: (0, _dedent.default)`
656
+ const myReusableTestBody = (value, snapshotHint) => {
657
+ expect(value).toMatchSnapshot();
658
+
659
+ const innerFn = anotherValue => {
660
+ expect(anotherValue).toMatchSnapshot();
661
+ };
662
+
663
+ expect(value).toBe(1);
664
+ expect(value + 1).toMatchSnapshot(null);
665
+ expect(value + 2).toThrowErrorMatchingSnapshot(snapshotHint);
666
+ };
667
+ `,
668
+ options: ['multi'],
669
+ errors: [{
670
+ messageId: 'missingHint',
671
+ column: 17,
672
+ line: 2
673
+ }, {
674
+ messageId: 'missingHint',
675
+ column: 26,
676
+ line: 5
677
+ }, {
678
+ messageId: 'missingHint',
679
+ column: 21,
680
+ line: 9
681
+ }]
682
+ }, {
683
+ code: (0, _dedent.default)`
684
+ const myReusableTestBody = (value, snapshotHint) => {
685
+ expect(value).toMatchSnapshot();
686
+
687
+ const innerFn = anotherValue => {
688
+ expect(anotherValue).toMatchSnapshot();
689
+
690
+ expect(value).toBe(1);
691
+ expect(value + 1).toMatchSnapshot(null);
692
+ expect(value + 2).toMatchSnapshot(null, snapshotHint);
693
+ };
694
+ };
695
+ `,
696
+ options: ['multi'],
697
+ errors: [{
698
+ messageId: 'missingHint',
699
+ column: 17,
700
+ line: 2
701
+ }, {
702
+ messageId: 'missingHint',
703
+ column: 26,
704
+ line: 5
705
+ }, {
706
+ messageId: 'missingHint',
707
+ column: 23,
708
+ line: 8
709
+ }]
710
+ }, {
711
+ code: (0, _dedent.default)`
712
+ const myReusableTestBody = (value, snapshotHint) => {
713
+ const innerFn = anotherValue => {
714
+ expect(anotherValue).toMatchSnapshot();
715
+
716
+ expect(value).toBe(1);
717
+ expect(value + 1).toMatchSnapshot(null);
718
+ expect(value + 2).toMatchSnapshot(null, snapshotHint);
719
+ };
720
+
721
+ expect(value).toThrowErrorMatchingSnapshot();
722
+ };
723
+ `,
724
+ options: ['multi'],
725
+ errors: [{
726
+ messageId: 'missingHint',
727
+ column: 26,
728
+ line: 3
729
+ }, {
730
+ messageId: 'missingHint',
731
+ column: 23,
732
+ line: 6
733
+ }, {
734
+ messageId: 'missingHint',
735
+ column: 17,
736
+ line: 10
737
+ }]
738
+ }, {
739
+ code: (0, _dedent.default)`
740
+ const myReusableTestBody = (value, snapshotHint) => {
741
+ const innerFn = anotherValue => {
742
+ expect(anotherValue).toMatchSnapshot();
743
+
744
+ expect(value).toBe(1);
745
+ };
746
+
747
+ expect(value).toMatchSnapshot();
748
+ };
749
+
750
+ it('my test', () => {
751
+ expect(1).toMatchSnapshot();
752
+ });
753
+ `,
754
+ options: ['multi'],
755
+ errors: [{
756
+ messageId: 'missingHint',
757
+ column: 26,
758
+ line: 3
759
+ }, {
760
+ messageId: 'missingHint',
761
+ column: 17,
762
+ line: 8
763
+ }]
764
+ }, {
765
+ code: (0, _dedent.default)`
766
+ const myReusableTestBody = value => {
767
+ expect(value).toMatchSnapshot();
768
+ };
769
+
770
+ expect(1).toMatchSnapshot();
771
+ expect(1).toThrowErrorMatchingSnapshot();
772
+ `,
773
+ options: ['multi'],
774
+ errors: [{
775
+ messageId: 'missingHint',
776
+ column: 11,
777
+ line: 5
778
+ }, {
779
+ messageId: 'missingHint',
780
+ column: 11,
781
+ line: 6
782
+ }]
783
+ }]
784
+ });