@@ -260,6 +260,40 @@ ruleTester.run(RULE_NAME, rule, {
260
260
})
261
261
` ,
262
262
} ,
263
+ ...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
264
+ code : `
265
+ function setup() {
266
+ const utils = render(<MyComponent />);
267
+
268
+ const waitForAsyncUtil = () => {
269
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
270
+ };
271
+
272
+ return { waitForAsyncUtil, ...utils };
273
+ }
274
+
275
+ test('destructuring an async function wrapper & handling it later is valid', () => {
276
+ const { user, waitForAsyncUtil } = setup();
277
+ await waitForAsyncUtil();
278
+
279
+ const myAlias = waitForAsyncUtil;
280
+ const myOtherAlias = myAlias;
281
+ await myAlias();
282
+ await myOtherAlias();
283
+
284
+ const { ...clone } = setup();
285
+ await clone.waitForAsyncUtil();
286
+
287
+ const { waitForAsyncUtil: myDestructuredAlias } = setup();
288
+ await myDestructuredAlias();
289
+
290
+ const { user, ...rest } = setup();
291
+ await rest.waitForAsyncUtil();
292
+
293
+ await setup().waitForAsyncUtil();
294
+ });
295
+ ` ,
296
+ } ) ) ,
263
297
] ) ,
264
298
invalid : SUPPORTED_TESTING_FRAMEWORKS . flatMap ( ( testingFramework ) => [
265
299
...ASYNC_UTILS . map (
@@ -441,6 +475,7 @@ ruleTester.run(RULE_NAME, rule, {
441
475
] ,
442
476
} as const )
443
477
) ,
478
+
444
479
...ASYNC_UTILS . map (
445
480
( asyncUtil ) =>
446
481
( {
@@ -463,5 +498,179 @@ ruleTester.run(RULE_NAME, rule, {
463
498
] ,
464
499
} as const )
465
500
) ,
501
+ ...ASYNC_UTILS . map (
502
+ ( asyncUtil ) =>
503
+ ( {
504
+ code : `
505
+ function setup() {
506
+ const utils = render(<MyComponent />);
507
+
508
+ const waitForAsyncUtil = () => {
509
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
510
+ };
511
+
512
+ return { waitForAsyncUtil, ...utils };
513
+ }
514
+
515
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
516
+ const { user, waitForAsyncUtil } = setup();
517
+ waitForAsyncUtil();
518
+ });
519
+ ` ,
520
+ errors : [
521
+ {
522
+ line : 14 ,
523
+ column : 11 ,
524
+ messageId : 'asyncUtilWrapper' ,
525
+ data : { name : 'waitForAsyncUtil' } ,
526
+ } ,
527
+ ] ,
528
+ } as const )
529
+ ) ,
530
+ ...ASYNC_UTILS . map (
531
+ ( asyncUtil ) =>
532
+ ( {
533
+ code : `
534
+ function setup() {
535
+ const utils = render(<MyComponent />);
536
+
537
+ const waitForAsyncUtil = () => {
538
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
539
+ };
540
+
541
+ return { waitForAsyncUtil, ...utils };
542
+ }
543
+
544
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
545
+ const { user, waitForAsyncUtil } = setup();
546
+ const myAlias = waitForAsyncUtil;
547
+ myAlias();
548
+ });
549
+ ` ,
550
+ errors : [
551
+ {
552
+ line : 15 ,
553
+ column : 11 ,
554
+ messageId : 'asyncUtilWrapper' ,
555
+ data : { name : 'myAlias' } ,
556
+ } ,
557
+ ] ,
558
+ } as const )
559
+ ) ,
560
+ ...ASYNC_UTILS . map (
561
+ ( asyncUtil ) =>
562
+ ( {
563
+ code : `
564
+ function setup() {
565
+ const utils = render(<MyComponent />);
566
+
567
+ const waitForAsyncUtil = () => {
568
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
569
+ };
570
+
571
+ return { waitForAsyncUtil, ...utils };
572
+ }
573
+
574
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
575
+ const { ...clone } = setup();
576
+ clone.waitForAsyncUtil();
577
+ });
578
+ ` ,
579
+ errors : [
580
+ {
581
+ line : 14 ,
582
+ column : 17 ,
583
+ messageId : 'asyncUtilWrapper' ,
584
+ data : { name : 'waitForAsyncUtil' } ,
585
+ } ,
586
+ ] ,
587
+ } as const )
588
+ ) ,
589
+ ...ASYNC_UTILS . map (
590
+ ( asyncUtil ) =>
591
+ ( {
592
+ code : `
593
+ function setup() {
594
+ const utils = render(<MyComponent />);
595
+
596
+ const waitForAsyncUtil = () => {
597
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
598
+ };
599
+
600
+ return { waitForAsyncUtil, ...utils };
601
+ }
602
+
603
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
604
+ const { waitForAsyncUtil: myAlias } = setup();
605
+ myAlias();
606
+ });
607
+ ` ,
608
+ errors : [
609
+ {
610
+ line : 14 ,
611
+ column : 11 ,
612
+ messageId : 'asyncUtilWrapper' ,
613
+ data : { name : 'myAlias' } ,
614
+ } ,
615
+ ] ,
616
+ } as const )
617
+ ) ,
618
+ ...ASYNC_UTILS . map (
619
+ ( asyncUtil ) =>
620
+ ( {
621
+ code : `
622
+ function setup() {
623
+ const utils = render(<MyComponent />);
624
+
625
+ const waitForAsyncUtil = () => {
626
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
627
+ };
628
+
629
+ return { waitForAsyncUtil, ...utils };
630
+ }
631
+
632
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
633
+ setup().waitForAsyncUtil();
634
+ });
635
+ ` ,
636
+ errors : [
637
+ {
638
+ line : 13 ,
639
+ column : 19 ,
640
+ messageId : 'asyncUtilWrapper' ,
641
+ data : { name : 'waitForAsyncUtil' } ,
642
+ } ,
643
+ ] ,
644
+ } as const )
645
+ ) ,
646
+ ...ASYNC_UTILS . map (
647
+ ( asyncUtil ) =>
648
+ ( {
649
+ code : `
650
+ function setup() {
651
+ const utils = render(<MyComponent />);
652
+
653
+ const waitForAsyncUtil = () => {
654
+ return ${ asyncUtil } (screen.queryByTestId('my-test-id'));
655
+ };
656
+
657
+ return { waitForAsyncUtil, ...utils };
658
+ }
659
+
660
+ test('unhandled promise from destructed property of async function wrapper is invalid', () => {
661
+ const myAlias = setup().waitForAsyncUtil;
662
+ myAlias();
663
+ });
664
+ ` ,
665
+ errors : [
666
+ {
667
+ line : 14 ,
668
+ column : 11 ,
669
+ messageId : 'asyncUtilWrapper' ,
670
+ data : { name : 'myAlias' } ,
671
+ } ,
672
+ ] ,
673
+ } as const )
674
+ ) ,
466
675
] ) ,
467
676
} ) ;
0 commit comments