Skip to content

Commit c0b6e6f

Browse files
authored
fix(await-async-events): sync userEvent.setup() should not be reported (#817)
Fixes #800 Co-authored-by: Justin Toman <--global>
1 parent 8b0b9cc commit c0b6e6f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/rules/await-async-events.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const RULE_NAME = 'await-async-events';
1616
export type MessageIds = 'awaitAsyncEvent' | 'awaitAsyncEventWrapper';
1717
const FIRE_EVENT_NAME = 'fireEvent';
1818
const USER_EVENT_NAME = 'userEvent';
19+
const USER_EVENT_SETUP_FUNCTION_NAME = 'setup';
1920
type EventModules = (typeof EVENTS_SIMULATORS)[number];
2021
export type Options = [
2122
{
@@ -90,6 +91,9 @@ export default createTestingLibraryRule<Options, MessageIds>({
9091
messageId?: MessageIds;
9192
fix?: TSESLint.ReportFixFunction;
9293
}): void {
94+
if (node.name === USER_EVENT_SETUP_FUNCTION_NAME) {
95+
return;
96+
}
9397
if (!isPromiseHandled(node)) {
9498
context.report({
9599
node: closestCallExpression.callee,

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

+23
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,29 @@ ruleTester.run(RULE_NAME, rule, {
181181
]),
182182

183183
...USER_EVENT_ASYNC_FRAMEWORKS.flatMap((testingFramework) => [
184+
{
185+
code: `
186+
import userEvent from '${testingFramework}'
187+
test('setup method called is valid', () => {
188+
userEvent.setup()
189+
})
190+
`,
191+
options: [{ eventModule: 'userEvent' }] as const,
192+
},
193+
{
194+
code: `
195+
import userEvent from '${testingFramework}'
196+
function customSetup() {
197+
return {
198+
user: userEvent.setup()
199+
};
200+
}
201+
test('setup method called and returned is valid', () => {
202+
const {user} = customSetup();
203+
})
204+
`,
205+
options: [{ eventModule: 'userEvent' }] as const,
206+
},
184207
...USER_EVENT_ASYNC_FUNCTIONS.map((eventMethod) => ({
185208
code: `
186209
import userEvent from '${testingFramework}'

0 commit comments

Comments
 (0)