From a1bb21ea01e2a7cfa393e5e360aa3d620098efae Mon Sep 17 00:00:00 2001 From: Aleksei Androsov Date: Thu, 9 Nov 2023 11:53:32 +0300 Subject: [PATCH] fix(await-async-events): avoid reporting `userEvent.setup()` in wrappers (#834) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(await-async-events): sync userEvent.setup() should not be reported Better fix for #800 Co-authored-by: Mario Beltrán --- 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}'