Skip to content

Commit a1bb21e

Browse files
doochikBelco90
andauthored
fix(await-async-events): avoid reporting userEvent.setup() in wrappers (#834)
fix(await-async-events): sync userEvent.setup() should not be reported Better fix for #800 Co-authored-by: Mario Beltrán <[email protected]>
1 parent ce815e5 commit a1bb21e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: lib/rules/await-async-events.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ export default createTestingLibraryRule<Options, MessageIds>({
9191
messageId?: MessageIds;
9292
fix?: TSESLint.ReportFixFunction;
9393
}): void {
94-
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
95-
return;
96-
}
9794
if (!isPromiseHandled(node)) {
9895
context.report({
9996
node: closestCallExpression.callee,
@@ -136,6 +133,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
136133
return;
137134
}
138135

136+
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
137+
return;
138+
}
139+
139140
const references = getVariableReferences(
140141
context,
141142
closestCallExpression.parent

Diff for: tests/lib/rules/await-async-events.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ ruleTester.run(RULE_NAME, rule, {
204204
`,
205205
options: [{ eventModule: 'userEvent' }] as const,
206206
},
207+
{
208+
code: `
209+
import userEvent from '${testingFramework}'
210+
function customSetup() {
211+
const user = userEvent.setup();
212+
return { user };
213+
}
214+
test('setup method called and returned is valid', () => {
215+
const { user } = customSetup();
216+
})
217+
`,
218+
options: [{ eventModule: 'userEvent' }] as const,
219+
},
207220
...USER_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({
208221
code: `
209222
import userEvent from '${testingFramework}'

0 commit comments

Comments
 (0)