diff --git a/lib/rules/await-interactions.ts b/lib/rules/await-interactions.ts index d546250..9073721 100644 --- a/lib/rules/await-interactions.ts +++ b/lib/rules/await-interactions.ts @@ -73,6 +73,16 @@ export = createStorybookRule({ return null } + if ( + isMemberExpression(expr.callee) && + isIdentifier(expr.callee.object) && + isIdentifier(expr.callee.property) && + expr.callee.object.name === 'userEvent' && + expr.callee.property.name === 'setup' + ) { + return null + } + if ( isMemberExpression(expr.callee) && isIdentifier(expr.callee.object) && diff --git a/tests/lib/rules/await-interactions.test.ts b/tests/lib/rules/await-interactions.test.ts index 3e21255..bf969ef 100644 --- a/tests/lib/rules/await-interactions.test.ts +++ b/tests/lib/rules/await-interactions.test.ts @@ -110,6 +110,14 @@ ruleTester.run('await-interactions', rule, { } } `, + dedent` + export const Story = { + play: async ({canvasElement}) => { + const user = userEvent.setup(); + await user.click(button); + }, + }; + `, ], invalid: [ { @@ -376,5 +384,52 @@ ruleTester.run('await-interactions', rule, { }, ], }, + { + code: dedent` + export const Story = { + play: async ({canvasElement}) => { + const user = await userEvent.setup(); + }, + }; + `, + output: dedent` + export const Story = { + play: async ({canvasElement}) => { + const user = userEvent.setup(); + }, + }; + `, + errors: [ + { + // @ts-ignore + messageId: 'setupShouldNotBeAwaited', + data: { method: 'play' }, + }, + ], + }, + { + code: dedent` + export const Story = { + play: async ({canvasElement}) => { + const user = userEvent.setup(); + user.click(button); + }, + }; + `, + output: dedent` + export const Story = { + play: async ({canvasElement}) => { + const user = userEvent.setup(); + await user.click(button); + }, + }; + `, + errors: [ + { + messageId: 'interactionShouldBeAwaited', + data: { method: 'play' }, + }, + ], + }, ], })