Skip to content
Draft
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
10 changes: 10 additions & 0 deletions lib/rules/await-interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
55 changes: 55 additions & 0 deletions tests/lib/rules/await-interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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' },
},
],
},
],
})