Skip to content

Commit ce0cf94

Browse files
committed
test(await-async-utils): map through ASYNC_UTILS in the test cases
1 parent 85644d6 commit ce0cf94

File tree

1 file changed

+131
-119
lines changed

1 file changed

+131
-119
lines changed

tests/lib/rules/await-async-utils.test.ts

+131-119
Original file line numberDiff line numberDiff line change
@@ -260,40 +260,40 @@ ruleTester.run(RULE_NAME, rule, {
260260
})
261261
`,
262262
},
263-
{
263+
...ASYNC_UTILS.map((asyncUtil) => ({
264264
code: `
265265
function setup() {
266266
const utils = render(<MyComponent />);
267267
268-
const waitForLoadComplete = () => {
269-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
268+
const waitForAsyncUtil = () => {
269+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
270270
};
271271
272-
return { waitForLoadComplete, ...utils };
272+
return { waitForAsyncUtil, ...utils };
273273
}
274274
275275
test('destructuring an async function wrapper & handling it later is valid', () => {
276-
const { user, waitForLoadComplete } = setup();
277-
await waitForLoadComplete();
276+
const { user, waitForAsyncUtil } = setup();
277+
await waitForAsyncUtil();
278278
279-
const myAlias = waitForLoadComplete;
279+
const myAlias = waitForAsyncUtil;
280280
const myOtherAlias = myAlias;
281281
await myAlias();
282282
await myOtherAlias();
283283
284284
const { ...clone } = setup();
285-
await clone.waitForLoadComplete();
285+
await clone.waitForAsyncUtil();
286286
287-
const { waitForLoadComplete: myDestructuredAlias } = setup();
287+
const { waitForAsyncUtil: myDestructuredAlias } = setup();
288288
await myDestructuredAlias();
289289
290290
const { user, ...rest } = setup();
291-
await rest.waitForLoadComplete();
291+
await rest.waitForAsyncUtil();
292292
293-
await setup().waitForLoadComplete();
293+
await setup().waitForAsyncUtil();
294294
});
295295
`,
296-
},
296+
})),
297297
]),
298298
invalid: SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [
299299
...ASYNC_UTILS.map(
@@ -498,167 +498,179 @@ ruleTester.run(RULE_NAME, rule, {
498498
],
499499
} as const)
500500
),
501-
502-
{
503-
code: `
501+
...ASYNC_UTILS.map(
502+
(asyncUtil) =>
503+
({
504+
code: `
504505
function setup() {
505506
const utils = render(<MyComponent />);
506507
507-
const waitForLoadComplete = () => {
508-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
508+
const waitForAsyncUtil = () => {
509+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
509510
};
510511
511-
return { waitForLoadComplete, ...utils };
512+
return { waitForAsyncUtil, ...utils };
512513
}
513514
514515
test('unhandled promise from destructed property of async function wrapper is invalid', () => {
515-
const { user, waitForLoadComplete } = setup();
516-
waitForLoadComplete();
517-
});
518-
`,
519-
errors: [
520-
{
521-
line: 14,
522-
column: 11,
523-
messageId: 'asyncUtilWrapper',
524-
data: { name: 'waitForLoadComplete' },
525-
},
526-
],
527-
},
528-
529-
{
530-
code: `
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: `
531534
function setup() {
532535
const utils = render(<MyComponent />);
533536
534-
const waitForLoadComplete = () => {
535-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
537+
const waitForAsyncUtil = () => {
538+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
536539
};
537540
538-
return { waitForLoadComplete, ...utils };
541+
return { waitForAsyncUtil, ...utils };
539542
}
540543
541-
test('unhandled promise from assigning async function wrapper is invalid', () => {
542-
const { user, waitForLoadComplete } = setup();
543-
const myAlias = waitForLoadComplete;
544+
test('unhandled promise from destructed property of async function wrapper is invalid', () => {
545+
const { user, waitForAsyncUtil } = setup();
546+
const myAlias = waitForAsyncUtil;
544547
myAlias();
545548
});
546549
`,
547-
errors: [
548-
{
549-
line: 15,
550-
column: 11,
551-
messageId: 'asyncUtilWrapper',
552-
data: { name: 'myAlias' },
553-
},
554-
],
555-
},
556-
557-
{
558-
code: `
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: `
559564
function setup() {
560565
const utils = render(<MyComponent />);
561566
562-
const waitForLoadComplete = () => {
563-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
567+
const waitForAsyncUtil = () => {
568+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
564569
};
565570
566-
return { waitForLoadComplete, ...utils };
571+
return { waitForAsyncUtil, ...utils };
567572
}
568573
569-
test('unhandled promise from rest element with async wrapper function member is invalid', () => {
574+
test('unhandled promise from destructed property of async function wrapper is invalid', () => {
570575
const { ...clone } = setup();
571-
clone.waitForLoadComplete();
576+
clone.waitForAsyncUtil();
572577
});
573578
`,
574-
errors: [
575-
{
576-
line: 14,
577-
column: 17,
578-
messageId: 'asyncUtilWrapper',
579-
data: { name: 'waitForLoadComplete' },
580-
},
581-
],
582-
},
583-
584-
{
585-
code: `
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: `
586593
function setup() {
587594
const utils = render(<MyComponent />);
588595
589-
const waitForLoadComplete = () => {
590-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
596+
const waitForAsyncUtil = () => {
597+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
591598
};
592599
593-
return { waitForLoadComplete, ...utils };
600+
return { waitForAsyncUtil, ...utils };
594601
}
595602
596-
test('unhandled promise from destructured property alias is invalid', () => {
597-
const { waitForLoadComplete: myAlias } = setup();
603+
test('unhandled promise from destructed property of async function wrapper is invalid', () => {
604+
const { waitForAsyncUtil: myAlias } = setup();
598605
myAlias();
599606
});
600607
`,
601-
errors: [
602-
{
603-
line: 14,
604-
column: 11,
605-
messageId: 'asyncUtilWrapper',
606-
data: { name: 'myAlias' },
607-
},
608-
],
609-
},
610-
611-
{
612-
code: `
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: `
613622
function setup() {
614623
const utils = render(<MyComponent />);
615624
616-
const waitForLoadComplete = () => {
617-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
625+
const waitForAsyncUtil = () => {
626+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
618627
};
619628
620-
return { waitForLoadComplete, ...utils };
629+
return { waitForAsyncUtil, ...utils };
621630
}
622631
623-
test('unhandled promise from object member with async wrapper value is invalid', () => {
624-
setup().waitForLoadComplete();
625-
});
626-
`,
627-
errors: [
628-
{
629-
line: 13,
630-
column: 19,
631-
messageId: 'asyncUtilWrapper',
632-
data: { name: 'waitForLoadComplete' },
633-
},
634-
],
635-
},
636-
637-
{
638-
code: `
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: `
639650
function setup() {
640651
const utils = render(<MyComponent />);
641652
642-
const waitForLoadComplete = () => {
643-
return waitForElementToBeRemoved(screen.queryByTestId('my-test-id'));
653+
const waitForAsyncUtil = () => {
654+
return ${asyncUtil}(screen.queryByTestId('my-test-id'));
644655
};
645656
646-
return { waitForLoadComplete, ...utils };
657+
return { waitForAsyncUtil, ...utils };
647658
}
648659
649-
test('unhandled promise from object member with async wrapper value is invalid', () => {
650-
const myAlias = setup().waitForLoadComplete;
660+
test('unhandled promise from destructed property of async function wrapper is invalid', () => {
661+
const myAlias = setup().waitForAsyncUtil;
651662
myAlias();
652663
});
653664
`,
654-
errors: [
655-
{
656-
line: 14,
657-
column: 11,
658-
messageId: 'asyncUtilWrapper',
659-
data: { name: 'myAlias' },
660-
},
661-
],
662-
},
665+
errors: [
666+
{
667+
line: 14,
668+
column: 11,
669+
messageId: 'asyncUtilWrapper',
670+
data: { name: 'myAlias' },
671+
},
672+
],
673+
} as const)
674+
),
663675
]),
664676
});

0 commit comments

Comments
 (0)