@@ -347,6 +347,13 @@ ruleTester.run(RULE_NAME, rule, {
347
347
data : { name : asyncUtil } ,
348
348
} ,
349
349
] ,
350
+ output : `
351
+ import { ${ asyncUtil } } from '${ testingFramework } ';
352
+ test('${ asyncUtil } util not waited is invalid', () => {
353
+ doSomethingElse();
354
+ await ${ asyncUtil } (() => getByLabelText('email'));
355
+ });
356
+ ` ,
350
357
} ) as const
351
358
) ,
352
359
...ASYNC_UTILS . map (
@@ -367,6 +374,13 @@ ruleTester.run(RULE_NAME, rule, {
367
374
data : { name : asyncUtil } ,
368
375
} ,
369
376
] ,
377
+ output : `
378
+ import { ${ asyncUtil } } from '${ testingFramework } ';
379
+ test('${ asyncUtil } util not waited is invalid', () => {
380
+ doSomethingElse();
381
+ const el = await ${ asyncUtil } (() => getByLabelText('email'));
382
+ });
383
+ ` ,
370
384
} ) as const
371
385
) ,
372
386
...ASYNC_UTILS . map (
@@ -387,6 +401,13 @@ ruleTester.run(RULE_NAME, rule, {
387
401
data : { name : asyncUtil } ,
388
402
} ,
389
403
] ,
404
+ output : `
405
+ import * as asyncUtil from '${ testingFramework } ';
406
+ test('asyncUtil.${ asyncUtil } util not handled is invalid', () => {
407
+ doSomethingElse();
408
+ await asyncUtil.${ asyncUtil } (() => getByLabelText('email'));
409
+ });
410
+ ` ,
390
411
} ) as const
391
412
) ,
392
413
...ASYNC_UTILS . map (
@@ -407,6 +428,13 @@ ruleTester.run(RULE_NAME, rule, {
407
428
data : { name : asyncUtil } ,
408
429
} ,
409
430
] ,
431
+ output : `
432
+ import { ${ asyncUtil } } from '${ testingFramework } ';
433
+ test('${ asyncUtil } util promise saved not handled is invalid', () => {
434
+ doSomethingElse();
435
+ const aPromise = await ${ asyncUtil } (() => getByLabelText('email'));
436
+ });
437
+ ` ,
410
438
} ) as const
411
439
) ,
412
440
...ASYNC_UTILS . map (
@@ -434,6 +462,14 @@ ruleTester.run(RULE_NAME, rule, {
434
462
data : { name : asyncUtil } ,
435
463
} ,
436
464
] ,
465
+ output : `
466
+ import { ${ asyncUtil } } from '${ testingFramework } ';
467
+ test('several ${ asyncUtil } utils not handled are invalid', () => {
468
+ const aPromise = ${ asyncUtil } (() => getByLabelText('username'));
469
+ doSomethingElse(aPromise);
470
+ await ${ asyncUtil } (() => getByLabelText('email'));
471
+ });
472
+ ` ,
437
473
} ) as const
438
474
) ,
439
475
...ASYNC_UTILS . map (
@@ -461,6 +497,14 @@ ruleTester.run(RULE_NAME, rule, {
461
497
data : { name : asyncUtil } ,
462
498
} ,
463
499
] ,
500
+ output : `
501
+ import { ${ asyncUtil } } from '${ testingFramework } ';
502
+ test('unhandled expression that evaluates to promise is invalid', () => {
503
+ const aPromise = ${ asyncUtil } (() => getByLabelText('username'));
504
+ doSomethingElse(aPromise);
505
+ await ${ asyncUtil } (() => getByLabelText('email'));
506
+ });
507
+ ` ,
464
508
} ) as const
465
509
) ,
466
510
...ASYNC_UTILS . map (
@@ -486,6 +530,18 @@ ruleTester.run(RULE_NAME, rule, {
486
530
data : { name : 'waitForSomethingAsync' } ,
487
531
} ,
488
532
] ,
533
+ output : `
534
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
535
+
536
+ function waitForSomethingAsync() {
537
+ return ${ asyncUtil } (() => somethingAsync())
538
+ }
539
+
540
+ test('unhandled promise from function wrapping ${ asyncUtil } util is invalid', async () => {
541
+ render()
542
+ await waitForSomethingAsync()
543
+ });
544
+ ` ,
489
545
} ) as const
490
546
) ,
491
547
...ASYNC_UTILS . map (
@@ -508,6 +564,15 @@ ruleTester.run(RULE_NAME, rule, {
508
564
data : { name : asyncUtil } ,
509
565
} ,
510
566
] ,
567
+ output : `
568
+ import { ${ asyncUtil } } from 'some-other-library';
569
+ test(
570
+ 'aggressive reporting - util "${ asyncUtil } " which is not related to testing library is invalid',
571
+ async () => {
572
+ doSomethingElse();
573
+ await ${ asyncUtil } ();
574
+ });
575
+ ` ,
511
576
} ) as const
512
577
) ,
513
578
...ASYNC_UTILS . map (
@@ -533,6 +598,18 @@ ruleTester.run(RULE_NAME, rule, {
533
598
data : { name : 'waitForSomethingAsync' } ,
534
599
} ,
535
600
] ,
601
+ output : `
602
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
603
+
604
+ function waitForSomethingAsync() {
605
+ return ${ asyncUtil } (() => somethingAsync())
606
+ }
607
+
608
+ test('unhandled promise from function wrapping ${ asyncUtil } util is invalid', async () => {
609
+ render()
610
+ const el = await waitForSomethingAsync()
611
+ });
612
+ ` ,
536
613
} ) as const
537
614
) ,
538
615
@@ -556,6 +633,15 @@ ruleTester.run(RULE_NAME, rule, {
556
633
data : { name : asyncUtil } ,
557
634
} ,
558
635
] ,
636
+ output : `
637
+ import * as asyncUtils from 'some-other-library';
638
+ test(
639
+ 'aggressive reporting - util "asyncUtils.${ asyncUtil } " which is not related to testing library is invalid',
640
+ async () => {
641
+ doSomethingElse();
642
+ await asyncUtils.${ asyncUtil } ();
643
+ });
644
+ ` ,
559
645
} ) as const
560
646
) ,
561
647
...ASYNC_UTILS . map (
@@ -586,6 +672,22 @@ ruleTester.run(RULE_NAME, rule, {
586
672
data : { name : 'waitForAsyncUtil' } ,
587
673
} ,
588
674
] ,
675
+ output : `
676
+ function setup() {
677
+ const utils = render(<MyComponent />);
678
+
679
+ const waitForAsyncUtil = () => {
680
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
681
+ };
682
+
683
+ return { waitForAsyncUtil, ...utils };
684
+ }
685
+
686
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
687
+ const { user, waitForAsyncUtil } = setup();
688
+ await waitForAsyncUtil();
689
+ });
690
+ ` ,
589
691
} ) as const
590
692
) ,
591
693
...ASYNC_UTILS . map (
@@ -617,6 +719,23 @@ ruleTester.run(RULE_NAME, rule, {
617
719
data : { name : 'myAlias' } ,
618
720
} ,
619
721
] ,
722
+ output : `
723
+ function setup() {
724
+ const utils = render(<MyComponent />);
725
+
726
+ const waitForAsyncUtil = () => {
727
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
728
+ };
729
+
730
+ return { waitForAsyncUtil, ...utils };
731
+ }
732
+
733
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
734
+ const { user, waitForAsyncUtil } = setup();
735
+ const myAlias = waitForAsyncUtil;
736
+ await myAlias();
737
+ });
738
+ ` ,
620
739
} ) as const
621
740
) ,
622
741
...ASYNC_UTILS . map (
@@ -647,6 +766,22 @@ ruleTester.run(RULE_NAME, rule, {
647
766
data : { name : 'waitForAsyncUtil' } ,
648
767
} ,
649
768
] ,
769
+ output : `
770
+ function setup() {
771
+ const utils = render(<MyComponent />);
772
+
773
+ const waitForAsyncUtil = () => {
774
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
775
+ };
776
+
777
+ return { waitForAsyncUtil, ...utils };
778
+ }
779
+
780
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
781
+ const { ...clone } = setup();
782
+ await clone.waitForAsyncUtil();
783
+ });
784
+ ` ,
650
785
} ) as const
651
786
) ,
652
787
...ASYNC_UTILS . map (
@@ -677,6 +812,22 @@ ruleTester.run(RULE_NAME, rule, {
677
812
data : { name : 'myAlias' } ,
678
813
} ,
679
814
] ,
815
+ output : `
816
+ function setup() {
817
+ const utils = render(<MyComponent />);
818
+
819
+ const waitForAsyncUtil = () => {
820
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
821
+ };
822
+
823
+ return { waitForAsyncUtil, ...utils };
824
+ }
825
+
826
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
827
+ const { waitForAsyncUtil: myAlias } = setup();
828
+ await myAlias();
829
+ });
830
+ ` ,
680
831
} ) as const
681
832
) ,
682
833
...ASYNC_UTILS . map (
@@ -706,6 +857,21 @@ ruleTester.run(RULE_NAME, rule, {
706
857
data : { name : 'waitForAsyncUtil' } ,
707
858
} ,
708
859
] ,
860
+ output : `
861
+ function setup() {
862
+ const utils = render(<MyComponent />);
863
+
864
+ const waitForAsyncUtil = () => {
865
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
866
+ };
867
+
868
+ return { waitForAsyncUtil, ...utils };
869
+ }
870
+
871
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
872
+ await setup().waitForAsyncUtil();
873
+ });
874
+ ` ,
709
875
} ) as const
710
876
) ,
711
877
...ASYNC_UTILS . map (
@@ -736,6 +902,22 @@ ruleTester.run(RULE_NAME, rule, {
736
902
data : { name : 'myAlias' } ,
737
903
} ,
738
904
] ,
905
+ output : `
906
+ function setup() {
907
+ const utils = render(<MyComponent />);
908
+
909
+ const waitForAsyncUtil = () => {
910
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
911
+ };
912
+
913
+ return { waitForAsyncUtil, ...utils };
914
+ }
915
+
916
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
917
+ const myAlias = setup().waitForAsyncUtil;
918
+ await myAlias();
919
+ });
920
+ ` ,
739
921
} ) as const
740
922
) ,
741
923
] ) ,
0 commit comments