Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(await-async-events): false positives for userEvent.setup() returned #895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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