Skip to content
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
4 changes: 4 additions & 0 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const RULE_NAME = 'await-async-events';
export type MessageIds = 'awaitAsyncEvent' | 'awaitAsyncEventWrapper';
const FIRE_EVENT_NAME = 'fireEvent';
const USER_EVENT_NAME = 'userEvent';
const USER_EVENT_SETUP_FUNCTION_NAME = 'setup';
type EventModules = (typeof EVENTS_SIMULATORS)[number];
export type Options = [
{
Expand Down Expand Up @@ -90,6 +91,9 @@ 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
23 changes: 23 additions & 0 deletions tests/lib/rules/await-async-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,29 @@ ruleTester.run(RULE_NAME, rule, {
]),

...USER_EVENT_ASYNC_FRAMEWORKS.flatMap((testingFramework) => [
{
code: `
import userEvent from '${testingFramework}'
test('setup method called is valid', () => {
userEvent.setup()
})
`,
options: [{ eventModule: 'userEvent' }] as const,
},
{
code: `
import userEvent from '${testingFramework}'
function customSetup() {
return {
user: userEvent.setup()
};
}
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