diff --git a/lib/rules/await-async-events.ts b/lib/rules/await-async-events.ts index 53c62659..96adfcb2 100644 --- a/lib/rules/await-async-events.ts +++ b/lib/rules/await-async-events.ts @@ -16,6 +16,7 @@ export const RULE_NAME = 'await-async-events'; export type MessageIds = 'awaitAsyncEvent' | 'awaitAsyncEventWrapper'; const FIRE_EVENT_NAME = 'fireEvent'; const USER_EVENT_NAME = 'userEvent'; +const USER_EVENT_SETUP_FUNCTION_NAME = 'setup'; type EventModules = (typeof EVENTS_SIMULATORS)[number]; export type Options = [ { @@ -90,6 +91,9 @@ export default createTestingLibraryRule({ messageId?: MessageIds; fix?: TSESLint.ReportFixFunction; }): void { + if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) { + return; + } if (!isPromiseHandled(node)) { context.report({ node: closestCallExpression.callee, diff --git a/tests/lib/rules/await-async-events.test.ts b/tests/lib/rules/await-async-events.test.ts index fe133c0c..2f0ce78e 100644 --- a/tests/lib/rules/await-async-events.test.ts +++ b/tests/lib/rules/await-async-events.test.ts @@ -181,6 +181,29 @@ ruleTester.run(RULE_NAME, rule, { ]), ...USER_EVENT_ASYNC_FRAMEWORKS.flatMap((testingFramework) => [ + { + code: ` + import userEvent from '${testingFramework}' + test('setup method called is valid', () => { + userEvent.setup() + }) + `, + options: [{ eventModule: 'userEvent' }] as const, + }, + { + code: ` + import userEvent from '${testingFramework}' + function customSetup() { + return { + user: userEvent.setup() + }; + } + test('setup method called and returned is valid', () => { + const {user} = customSetup(); + }) + `, + options: [{ eventModule: 'userEvent' }] as const, + }, ...USER_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({ code: ` import userEvent from '${testingFramework}'