Skip to content

Commit

Permalink
fix(await-async-events): avoid reporting userEvent.setup() in wrapp…
Browse files Browse the repository at this point in the history
…ers (#834)

fix(await-async-events): sync userEvent.setup() should not be reported

Better fix for #800

Co-authored-by: Mario Beltrán <belco90@gmail.com>
  • Loading branch information
doochik and Belco90 authored Nov 9, 2023
1 parent ce815e5 commit a1bb21e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export default createTestingLibraryRule<Options, MessageIds>({
messageId?: MessageIds;
fix?: TSESLint.ReportFixFunction;
}): void {
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
return;
}
if (!isPromiseHandled(node)) {
context.report({
node: closestCallExpression.callee,
Expand Down Expand Up @@ -136,6 +133,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
return;
}

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

const references = getVariableReferences(
context,
closestCallExpression.parent
Expand Down
13 changes: 13 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,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}'
Expand Down

0 comments on commit a1bb21e

Please sign in to comment.