diff --git a/lib/rules/await-async-events.ts b/lib/rules/await-async-events.ts index 96adfcb2..6ca29473 100644 --- a/lib/rules/await-async-events.ts +++ b/lib/rules/await-async-events.ts @@ -91,9 +91,6 @@ 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, @@ -136,6 +133,10 @@ export default createTestingLibraryRule({ return; } + if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) { + return; + } + const references = getVariableReferences( context, closestCallExpression.parent diff --git a/tests/lib/rules/await-async-events.test.ts b/tests/lib/rules/await-async-events.test.ts index 2f0ce78e..ba7110a5 100644 --- a/tests/lib/rules/await-async-events.test.ts +++ b/tests/lib/rules/await-async-events.test.ts @@ -204,6 +204,19 @@ ruleTester.run(RULE_NAME, rule, { `, options: [{ eventModule: 'userEvent' }] as const, }, + { + code: ` + import userEvent from '${testingFramework}' + function customSetup() { + const user = userEvent.setup(); + return { user }; + } + 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}'