Skip to content

Commit

Permalink
fix(await-async-events): sync userEvent.setup() should not be reported (
Browse files Browse the repository at this point in the history
#817)

Fixes #800

Co-authored-by: Justin Toman <--global>
  • Loading branch information
justintoman authored Sep 23, 2023
1 parent 8b0b9cc commit c0b6e6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit c0b6e6f

Please sign in to comment.