Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#132 await interactions false positive issue #142

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/rules/await-interactions.ts
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
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' },
},
],
},
],
})