From 47cf9f55abcb8168fe51cf2ebebd52e665ef3776 Mon Sep 17 00:00:00 2001 From: Aleksei Androsov Date: Tue, 24 Oct 2023 14:41:12 +0300 Subject: [PATCH] fix(await-async-events): sync userEvent.setup() should not be reported Better fix for #800 --- lib/rules/await-async-events.ts | 7 ++++--- tests/lib/rules/await-async-events.test.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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}'