Skip to content

Commit fb32c5c

Browse files
authored
fix(await-async-events): false positives for userEvent.setup() returned (#895)
1 parent 767f1be commit fb32c5c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/rules/await-async-events.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
122122
(isFireEventEnabled && helpers.isFireEventMethod(node)) ||
123123
(isUserEventEnabled && helpers.isUserEventMethod(node))
124124
) {
125+
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
126+
return;
127+
}
128+
125129
detectEventMethodWrapper(node);
126130

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

136-
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
137-
return;
138-
}
139-
140140
const references = getVariableReferences(
141141
context,
142142
closestCallExpression.parent

tests/lib/rules/await-async-events.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ ruleTester.run(RULE_NAME, rule, {
204204
`,
205205
options: [{ eventModule: 'userEvent' }] as const,
206206
},
207+
{
208+
code: `
209+
import userEvent from '${testingFramework}'
210+
const customSetup = () => userEvent.setup();
211+
test('setup method called and returned as arrow function body is valid', () => {
212+
const user = customSetup();
213+
})
214+
`,
215+
options: [{ eventModule: 'userEvent' }] as const,
216+
},
207217
{
208218
code: `
209219
import userEvent from '${testingFramework}'

0 commit comments

Comments
 (0)