@@ -157,6 +157,21 @@ ruleTester.run('prefer-snapshot-hint (always)', rule, {
157
157
} ,
158
158
] ,
159
159
} ,
160
+ {
161
+ code : dedent `
162
+ it('is true', () => {
163
+ { expect(1).toMatchSnapshot(); }
164
+ });
165
+ ` ,
166
+ options : [ 'always' ] ,
167
+ errors : [
168
+ {
169
+ messageId : 'missingHint' ,
170
+ column : 15 ,
171
+ line : 2 ,
172
+ } ,
173
+ ] ,
174
+ } ,
160
175
] ,
161
176
} ) ;
162
177
@@ -260,6 +275,57 @@ ruleTester.run('prefer-snapshot-hint (multi)', rule, {
260
275
` ,
261
276
options : [ 'multi' ] ,
262
277
} ,
278
+ {
279
+ code : dedent `
280
+ const myReusableTestBody = (value, snapshotHint) => {
281
+ const innerFn = anotherValue => {
282
+ expect(anotherValue).toMatchSnapshot();
283
+
284
+ expect(value).toBe(1);
285
+ };
286
+
287
+ expect(value).toBe(1);
288
+ };
289
+
290
+ it('my test', () => {
291
+ expect(1).toMatchSnapshot();
292
+ });
293
+ ` ,
294
+ options : [ 'multi' ] ,
295
+ } ,
296
+ {
297
+ code : dedent `
298
+ const myReusableTestBody = (value, snapshotHint) => {
299
+ const innerFn = anotherValue => {
300
+ expect(value).toBe(1);
301
+ };
302
+
303
+ expect(value).toBe(1);
304
+ expect(anotherValue).toMatchSnapshot();
305
+ };
306
+
307
+ it('my test', () => {
308
+ expect(1).toMatchSnapshot();
309
+ });
310
+ ` ,
311
+ options : [ 'multi' ] ,
312
+ } ,
313
+ {
314
+ code : dedent `
315
+ const myReusableTestBody = (value, snapshotHint) => {
316
+ const innerFn = anotherValue => {
317
+ expect(anotherValue).toMatchSnapshot();
318
+
319
+ expect(value).toBe(1);
320
+ };
321
+
322
+ expect(value).toBe(1);
323
+ };
324
+
325
+ expect(1).toMatchSnapshot();
326
+ ` ,
327
+ options : [ 'multi' ] ,
328
+ } ,
263
329
] ,
264
330
invalid : [
265
331
{
@@ -346,6 +412,50 @@ ruleTester.run('prefer-snapshot-hint (multi)', rule, {
346
412
} ,
347
413
] ,
348
414
} ,
415
+ {
416
+ code : dedent `
417
+ it('is true', () => {
418
+ expect(1).toMatchSnapshot({});
419
+ {
420
+ expect(2).toMatchSnapshot({});
421
+ }
422
+ });
423
+ ` ,
424
+ options : [ 'multi' ] ,
425
+ errors : [
426
+ {
427
+ messageId : 'missingHint' ,
428
+ column : 13 ,
429
+ line : 2 ,
430
+ } ,
431
+ {
432
+ messageId : 'missingHint' ,
433
+ column : 15 ,
434
+ line : 4 ,
435
+ } ,
436
+ ] ,
437
+ } ,
438
+ {
439
+ code : dedent `
440
+ it('is true', () => {
441
+ { expect(1).toMatchSnapshot(); }
442
+ { expect(2).toMatchSnapshot(); }
443
+ });
444
+ ` ,
445
+ options : [ 'multi' ] ,
446
+ errors : [
447
+ {
448
+ messageId : 'missingHint' ,
449
+ column : 15 ,
450
+ line : 2 ,
451
+ } ,
452
+ {
453
+ messageId : 'missingHint' ,
454
+ column : 15 ,
455
+ line : 3 ,
456
+ } ,
457
+ ] ,
458
+ } ,
349
459
{
350
460
code : dedent `
351
461
it('is true', () => {
@@ -460,5 +570,157 @@ ruleTester.run('prefer-snapshot-hint (multi)', rule, {
460
570
} ,
461
571
] ,
462
572
} ,
573
+ {
574
+ code : dedent `
575
+ const myReusableTestBody = (value, snapshotHint) => {
576
+ expect(value).toMatchSnapshot();
577
+
578
+ const innerFn = anotherValue => {
579
+ expect(anotherValue).toMatchSnapshot();
580
+ };
581
+
582
+ expect(value).toBe(1);
583
+ expect(value + 1).toMatchSnapshot(null);
584
+ expect(value + 2).toThrowErrorMatchingSnapshot(snapshotHint);
585
+ };
586
+ ` ,
587
+ options : [ 'multi' ] ,
588
+ errors : [
589
+ {
590
+ messageId : 'missingHint' ,
591
+ column : 17 ,
592
+ line : 2 ,
593
+ } ,
594
+ {
595
+ messageId : 'missingHint' ,
596
+ column : 26 ,
597
+ line : 5 ,
598
+ } ,
599
+ {
600
+ messageId : 'missingHint' ,
601
+ column : 21 ,
602
+ line : 9 ,
603
+ } ,
604
+ ] ,
605
+ } ,
606
+ {
607
+ code : dedent `
608
+ const myReusableTestBody = (value, snapshotHint) => {
609
+ expect(value).toMatchSnapshot();
610
+
611
+ const innerFn = anotherValue => {
612
+ expect(anotherValue).toMatchSnapshot();
613
+
614
+ expect(value).toBe(1);
615
+ expect(value + 1).toMatchSnapshot(null);
616
+ expect(value + 2).toMatchSnapshot(null, snapshotHint);
617
+ };
618
+ };
619
+ ` ,
620
+ options : [ 'multi' ] ,
621
+ errors : [
622
+ {
623
+ messageId : 'missingHint' ,
624
+ column : 17 ,
625
+ line : 2 ,
626
+ } ,
627
+ {
628
+ messageId : 'missingHint' ,
629
+ column : 26 ,
630
+ line : 5 ,
631
+ } ,
632
+ {
633
+ messageId : 'missingHint' ,
634
+ column : 23 ,
635
+ line : 8 ,
636
+ } ,
637
+ ] ,
638
+ } ,
639
+ {
640
+ code : dedent `
641
+ const myReusableTestBody = (value, snapshotHint) => {
642
+ const innerFn = anotherValue => {
643
+ expect(anotherValue).toMatchSnapshot();
644
+
645
+ expect(value).toBe(1);
646
+ expect(value + 1).toMatchSnapshot(null);
647
+ expect(value + 2).toMatchSnapshot(null, snapshotHint);
648
+ };
649
+
650
+ expect(value).toThrowErrorMatchingSnapshot();
651
+ };
652
+ ` ,
653
+ options : [ 'multi' ] ,
654
+ errors : [
655
+ {
656
+ messageId : 'missingHint' ,
657
+ column : 26 ,
658
+ line : 3 ,
659
+ } ,
660
+ {
661
+ messageId : 'missingHint' ,
662
+ column : 23 ,
663
+ line : 6 ,
664
+ } ,
665
+ {
666
+ messageId : 'missingHint' ,
667
+ column : 17 ,
668
+ line : 10 ,
669
+ } ,
670
+ ] ,
671
+ } ,
672
+ {
673
+ code : dedent `
674
+ const myReusableTestBody = (value, snapshotHint) => {
675
+ const innerFn = anotherValue => {
676
+ expect(anotherValue).toMatchSnapshot();
677
+
678
+ expect(value).toBe(1);
679
+ };
680
+
681
+ expect(value).toMatchSnapshot();
682
+ };
683
+
684
+ it('my test', () => {
685
+ expect(1).toMatchSnapshot();
686
+ });
687
+ ` ,
688
+ options : [ 'multi' ] ,
689
+ errors : [
690
+ {
691
+ messageId : 'missingHint' ,
692
+ column : 26 ,
693
+ line : 3 ,
694
+ } ,
695
+ {
696
+ messageId : 'missingHint' ,
697
+ column : 17 ,
698
+ line : 8 ,
699
+ } ,
700
+ ] ,
701
+ } ,
702
+ {
703
+ code : dedent `
704
+ const myReusableTestBody = value => {
705
+ expect(value).toMatchSnapshot();
706
+ };
707
+
708
+ expect(1).toMatchSnapshot();
709
+ expect(1).toThrowErrorMatchingSnapshot();
710
+ ` ,
711
+ options : [ 'multi' ] ,
712
+ errors : [
713
+ {
714
+ messageId : 'missingHint' ,
715
+ column : 11 ,
716
+ line : 5 ,
717
+ } ,
718
+ {
719
+ messageId : 'missingHint' ,
720
+ column : 11 ,
721
+ line : 6 ,
722
+ } ,
723
+ ] ,
724
+ } ,
463
725
] ,
464
726
} ) ;
0 commit comments