@@ -497,11 +497,26 @@ ruleTester.run(RULE_NAME, rule, {
497
497
const element = queryWrapper()
498
498
})
499
499
500
- test("An invalid example test", async () => {
500
+ test("A valid example test", async () => {
501
501
const element = await queryWrapper()
502
502
})
503
503
` ,
504
504
errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
505
+ output : `
506
+ function queryWrapper() {
507
+ doSomethingElse();
508
+
509
+ return screen.${ query } ('foo')
510
+ }
511
+
512
+ test("An invalid example test", async () => {
513
+ const element = await queryWrapper()
514
+ })
515
+
516
+ test("A valid example test", async () => {
517
+ const element = await queryWrapper()
518
+ })
519
+ ` ,
505
520
} as const )
506
521
) ,
507
522
// unhandled promise from async query arrow function wrapper is invalid
@@ -519,11 +534,26 @@ ruleTester.run(RULE_NAME, rule, {
519
534
const element = queryWrapper()
520
535
})
521
536
522
- test("An invalid example test", async () => {
537
+ test("A valid example test", async () => {
523
538
const element = await queryWrapper()
524
539
})
525
540
` ,
526
541
errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
542
+ output : `
543
+ const queryWrapper = () => {
544
+ doSomethingElse();
545
+
546
+ return ${ query } ('foo')
547
+ }
548
+
549
+ test("An invalid example test", async () => {
550
+ const element = await queryWrapper()
551
+ })
552
+
553
+ test("A valid example test", async () => {
554
+ const element = await queryWrapper()
555
+ })
556
+ ` ,
527
557
} as const )
528
558
) ,
529
559
// unhandled promise implicitly returned from async query arrow function wrapper is invalid
@@ -537,11 +567,22 @@ ruleTester.run(RULE_NAME, rule, {
537
567
const element = queryWrapper()
538
568
})
539
569
540
- test("An invalid example test", async () => {
570
+ test("A valid example test", async () => {
541
571
const element = await queryWrapper()
542
572
})
543
573
` ,
544
574
errors : [ { messageId : 'asyncQueryWrapper' , line : 5 , column : 27 } ] ,
575
+ output : `
576
+ const queryWrapper = () => screen.${ query } ('foo')
577
+
578
+ test("An invalid example test", async () => {
579
+ const element = await queryWrapper()
580
+ })
581
+
582
+ test("A valid example test", async () => {
583
+ const element = await queryWrapper()
584
+ })
585
+ ` ,
545
586
} as const )
546
587
) ,
547
588
@@ -589,6 +630,30 @@ ruleTester.run(RULE_NAME, rule, {
589
630
})
590
631
` ,
591
632
errors : [ { messageId : 'asyncQueryWrapper' , line : 19 , column : 34 } ] ,
633
+ output : `// similar to issue #359 but forcing an error in no-awaited wrapper
634
+ import { render, screen } from 'mocks/test-utils'
635
+ import userEvent from '@testing-library/user-event'
636
+
637
+ const testData = {
638
+ name: 'John Doe',
639
+
640
+ password: 'extremeSecret',
641
+ }
642
+
643
+ const selectors = {
644
+ username: () => screen.findByRole('textbox', { name: /username/i }),
645
+ email: () => screen.findByRole('textbox', { name: /e-mail/i }),
646
+ password: () => screen.findByLabelText(/password/i),
647
+ }
648
+
649
+ test('this is a valid case', async () => {
650
+ render(<SomeComponent />)
651
+ userEvent.type(await selectors.username(), testData.name) // <-- unhandled here
652
+ userEvent.type(await selectors.email(), testData.email)
653
+ userEvent.type(await selectors.password(), testData.password)
654
+ // ...
655
+ })
656
+ ` ,
592
657
} ,
593
658
] ,
594
659
} ) ;
0 commit comments