@@ -346,6 +346,13 @@ ruleTester.run(RULE_NAME, rule, {
346
346
data : { name : asyncUtil } ,
347
347
} ,
348
348
] ,
349
+ output : `
350
+ import { ${ asyncUtil } } from '${ testingFramework } ';
351
+ test('${ asyncUtil } util not waited is invalid', () => {
352
+ doSomethingElse();
353
+ await ${ asyncUtil } (() => getByLabelText('email'));
354
+ });
355
+ ` ,
349
356
} as const )
350
357
) ,
351
358
...ASYNC_UTILS . map (
@@ -366,6 +373,13 @@ ruleTester.run(RULE_NAME, rule, {
366
373
data : { name : asyncUtil } ,
367
374
} ,
368
375
] ,
376
+ output : `
377
+ import { ${ asyncUtil } } from '${ testingFramework } ';
378
+ test('${ asyncUtil } util not waited is invalid', () => {
379
+ doSomethingElse();
380
+ const el = await ${ asyncUtil } (() => getByLabelText('email'));
381
+ });
382
+ ` ,
369
383
} as const )
370
384
) ,
371
385
...ASYNC_UTILS . map (
@@ -386,6 +400,13 @@ ruleTester.run(RULE_NAME, rule, {
386
400
data : { name : asyncUtil } ,
387
401
} ,
388
402
] ,
403
+ output : `
404
+ import * as asyncUtil from '${ testingFramework } ';
405
+ test('asyncUtil.${ asyncUtil } util not handled is invalid', () => {
406
+ doSomethingElse();
407
+ await asyncUtil.${ asyncUtil } (() => getByLabelText('email'));
408
+ });
409
+ ` ,
389
410
} as const )
390
411
) ,
391
412
...ASYNC_UTILS . map (
@@ -406,6 +427,13 @@ ruleTester.run(RULE_NAME, rule, {
406
427
data : { name : asyncUtil } ,
407
428
} ,
408
429
] ,
430
+ output : `
431
+ import { ${ asyncUtil } } from '${ testingFramework } ';
432
+ test('${ asyncUtil } util promise saved not handled is invalid', () => {
433
+ doSomethingElse();
434
+ const aPromise = await ${ asyncUtil } (() => getByLabelText('email'));
435
+ });
436
+ ` ,
409
437
} as const )
410
438
) ,
411
439
...ASYNC_UTILS . map (
@@ -433,6 +461,14 @@ ruleTester.run(RULE_NAME, rule, {
433
461
data : { name : asyncUtil } ,
434
462
} ,
435
463
] ,
464
+ output : `
465
+ import { ${ asyncUtil } } from '${ testingFramework } ';
466
+ test('several ${ asyncUtil } utils not handled are invalid', () => {
467
+ const aPromise = ${ asyncUtil } (() => getByLabelText('username'));
468
+ doSomethingElse(aPromise);
469
+ await ${ asyncUtil } (() => getByLabelText('email'));
470
+ });
471
+ ` ,
436
472
} as const )
437
473
) ,
438
474
...ASYNC_UTILS . map (
@@ -460,6 +496,14 @@ ruleTester.run(RULE_NAME, rule, {
460
496
data : { name : asyncUtil } ,
461
497
} ,
462
498
] ,
499
+ output : `
500
+ import { ${ asyncUtil } } from '${ testingFramework } ';
501
+ test('unhandled expression that evaluates to promise is invalid', () => {
502
+ const aPromise = ${ asyncUtil } (() => getByLabelText('username'));
503
+ doSomethingElse(aPromise);
504
+ await ${ asyncUtil } (() => getByLabelText('email'));
505
+ });
506
+ ` ,
463
507
} as const )
464
508
) ,
465
509
...ASYNC_UTILS . map (
@@ -485,6 +529,18 @@ ruleTester.run(RULE_NAME, rule, {
485
529
data : { name : 'waitForSomethingAsync' } ,
486
530
} ,
487
531
] ,
532
+ output : `
533
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
534
+
535
+ function waitForSomethingAsync() {
536
+ return ${ asyncUtil } (() => somethingAsync())
537
+ }
538
+
539
+ test('unhandled promise from function wrapping ${ asyncUtil } util is invalid', async () => {
540
+ render()
541
+ await waitForSomethingAsync()
542
+ });
543
+ ` ,
488
544
} as const )
489
545
) ,
490
546
...ASYNC_UTILS . map (
@@ -507,6 +563,15 @@ ruleTester.run(RULE_NAME, rule, {
507
563
data : { name : asyncUtil } ,
508
564
} ,
509
565
] ,
566
+ output : `
567
+ import { ${ asyncUtil } } from 'some-other-library';
568
+ test(
569
+ 'aggressive reporting - util "${ asyncUtil } " which is not related to testing library is invalid',
570
+ async () => {
571
+ doSomethingElse();
572
+ await ${ asyncUtil } ();
573
+ });
574
+ ` ,
510
575
} as const )
511
576
) ,
512
577
...ASYNC_UTILS . map (
@@ -532,6 +597,18 @@ ruleTester.run(RULE_NAME, rule, {
532
597
data : { name : 'waitForSomethingAsync' } ,
533
598
} ,
534
599
] ,
600
+ output : `
601
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
602
+
603
+ function waitForSomethingAsync() {
604
+ return ${ asyncUtil } (() => somethingAsync())
605
+ }
606
+
607
+ test('unhandled promise from function wrapping ${ asyncUtil } util is invalid', async () => {
608
+ render()
609
+ const el = await waitForSomethingAsync()
610
+ });
611
+ ` ,
535
612
} as const )
536
613
) ,
537
614
@@ -555,6 +632,15 @@ ruleTester.run(RULE_NAME, rule, {
555
632
data : { name : asyncUtil } ,
556
633
} ,
557
634
] ,
635
+ output : `
636
+ import * as asyncUtils from 'some-other-library';
637
+ test(
638
+ 'aggressive reporting - util "asyncUtils.${ asyncUtil } " which is not related to testing library is invalid',
639
+ async () => {
640
+ doSomethingElse();
641
+ await asyncUtils.${ asyncUtil } ();
642
+ });
643
+ ` ,
558
644
} as const )
559
645
) ,
560
646
...ASYNC_UTILS . map (
@@ -563,11 +649,11 @@ ruleTester.run(RULE_NAME, rule, {
563
649
code : `
564
650
function setup() {
565
651
const utils = render(<MyComponent />);
566
-
652
+
567
653
const waitForAsyncUtil = () => {
568
654
return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
569
655
};
570
-
656
+
571
657
return { waitForAsyncUtil, ...utils };
572
658
}
573
659
@@ -584,6 +670,22 @@ ruleTester.run(RULE_NAME, rule, {
584
670
data : { name : 'waitForAsyncUtil' } ,
585
671
} ,
586
672
] ,
673
+ output : `
674
+ function setup() {
675
+ const utils = render(<MyComponent />);
676
+
677
+ const waitForAsyncUtil = () => {
678
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
679
+ };
680
+
681
+ return { waitForAsyncUtil, ...utils };
682
+ }
683
+
684
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
685
+ const { user, waitForAsyncUtil } = setup();
686
+ await waitForAsyncUtil();
687
+ });
688
+ ` ,
587
689
} as const )
588
690
) ,
589
691
...ASYNC_UTILS . map (
@@ -614,6 +716,23 @@ ruleTester.run(RULE_NAME, rule, {
614
716
data : { name : 'myAlias' } ,
615
717
} ,
616
718
] ,
719
+ output : `
720
+ function setup() {
721
+ const utils = render(<MyComponent />);
722
+
723
+ const waitForAsyncUtil = () => {
724
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
725
+ };
726
+
727
+ return { waitForAsyncUtil, ...utils };
728
+ }
729
+
730
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
731
+ const { user, waitForAsyncUtil } = setup();
732
+ const myAlias = waitForAsyncUtil;
733
+ await myAlias();
734
+ });
735
+ ` ,
617
736
} as const )
618
737
) ,
619
738
...ASYNC_UTILS . map (
@@ -643,6 +762,22 @@ ruleTester.run(RULE_NAME, rule, {
643
762
data : { name : 'waitForAsyncUtil' } ,
644
763
} ,
645
764
] ,
765
+ output : `
766
+ function setup() {
767
+ const utils = render(<MyComponent />);
768
+
769
+ const waitForAsyncUtil = () => {
770
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
771
+ };
772
+
773
+ return { waitForAsyncUtil, ...utils };
774
+ }
775
+
776
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
777
+ const { ...clone } = setup();
778
+ await clone.waitForAsyncUtil();
779
+ });
780
+ ` ,
646
781
} as const )
647
782
) ,
648
783
...ASYNC_UTILS . map (
@@ -672,6 +807,22 @@ ruleTester.run(RULE_NAME, rule, {
672
807
data : { name : 'myAlias' } ,
673
808
} ,
674
809
] ,
810
+ output : `
811
+ function setup() {
812
+ const utils = render(<MyComponent />);
813
+
814
+ const waitForAsyncUtil = () => {
815
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
816
+ };
817
+
818
+ return { waitForAsyncUtil, ...utils };
819
+ }
820
+
821
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
822
+ const { waitForAsyncUtil: myAlias } = setup();
823
+ await myAlias();
824
+ });
825
+ ` ,
675
826
} as const )
676
827
) ,
677
828
...ASYNC_UTILS . map (
@@ -700,6 +851,21 @@ ruleTester.run(RULE_NAME, rule, {
700
851
data : { name : 'waitForAsyncUtil' } ,
701
852
} ,
702
853
] ,
854
+ output : `
855
+ function setup() {
856
+ const utils = render(<MyComponent />);
857
+
858
+ const waitForAsyncUtil = () => {
859
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
860
+ };
861
+
862
+ return { waitForAsyncUtil, ...utils };
863
+ }
864
+
865
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
866
+ await setup().waitForAsyncUtil();
867
+ });
868
+ ` ,
703
869
} as const )
704
870
) ,
705
871
...ASYNC_UTILS . map (
@@ -729,6 +895,22 @@ ruleTester.run(RULE_NAME, rule, {
729
895
data : { name : 'myAlias' } ,
730
896
} ,
731
897
] ,
898
+ output : `
899
+ function setup() {
900
+ const utils = render(<MyComponent />);
901
+
902
+ const waitForAsyncUtil = () => {
903
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
904
+ };
905
+
906
+ return { waitForAsyncUtil, ...utils };
907
+ }
908
+
909
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
910
+ const myAlias = setup().waitForAsyncUtil;
911
+ await myAlias();
912
+ });
913
+ ` ,
732
914
} as const )
733
915
) ,
734
916
] ) ,
0 commit comments