Skip to content

Commit

Permalink
fix(await-async-events): false positives for userEvent.setup() return…
Browse files Browse the repository at this point in the history
…ed (#895)
  • Loading branch information
Chamion committed Apr 15, 2024
1 parent 767f1be commit fb32c5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rules/await-async-events.ts
Expand Up @@ -122,6 +122,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
(isFireEventEnabled && helpers.isFireEventMethod(node)) ||
(isUserEventEnabled && helpers.isUserEventMethod(node))
) {
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
return;
}

detectEventMethodWrapper(node);

const closestCallExpression = findClosestCallExpressionNode(
Expand All @@ -133,10 +137,6 @@ export default createTestingLibraryRule<Options, MessageIds>({
return;
}

if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
return;
}

const references = getVariableReferences(
context,
closestCallExpression.parent
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/await-async-events.test.ts
Expand Up @@ -204,6 +204,16 @@ ruleTester.run(RULE_NAME, rule, {
`,
options: [{ eventModule: 'userEvent' }] as const,
},
{
code: `
import userEvent from '${testingFramework}'
const customSetup = () => userEvent.setup();
test('setup method called and returned as arrow function body is valid', () => {
const user = customSetup();
})
`,
options: [{ eventModule: 'userEvent' }] as const,
},
{
code: `
import userEvent from '${testingFramework}'
Expand Down

0 comments on commit fb32c5c

Please sign in to comment.