Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit ce8985b

Browse files
committed
Make sure that await interaction works with @storybook/test
1 parent 4a7c900 commit ce8985b

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

lib/rules/await-interactions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export = createStorybookRule({
132132

133133
const isUserEventFromStorybookImported = (node: TSESTree.ImportDeclaration) => {
134134
return (
135-
node.source.value === '@storybook/testing-library' &&
135+
(node.source.value === '@storybook/testing-library' ||
136+
node.source.value === '@storybook/test') &&
136137
node.specifiers.find(
137138
(spec) =>
138139
isImportSpecifier(spec) &&
@@ -144,7 +145,7 @@ export = createStorybookRule({
144145

145146
const isExpectFromStorybookImported = (node: TSESTree.ImportDeclaration) => {
146147
return (
147-
node.source.value === '@storybook/jest' &&
148+
(node.source.value === '@storybook/jest' || node.source.value === '@storybook/test') &&
148149
node.specifiers.find(
149150
(spec) => isImportSpecifier(spec) && spec.imported.name === 'expect'
150151
) !== undefined

tests/lib/rules/await-interactions.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,61 @@ ruleTester.run('await-interactions', rule, {
146146
},
147147
],
148148
},
149+
{
150+
code: dedent`
151+
import { expect, findByText } from '@storybook/test'
152+
WithModalOpen.play = async ({ args }) => {
153+
// should complain
154+
expect(args.onClick).toHaveBeenCalled()
155+
const element = findByText(canvasElement, 'asdf')
156+
}
157+
`,
158+
output: dedent`
159+
import { expect, findByText } from '@storybook/test'
160+
WithModalOpen.play = async ({ args }) => {
161+
// should complain
162+
await expect(args.onClick).toHaveBeenCalled()
163+
const element = await findByText(canvasElement, 'asdf')
164+
}
165+
`,
166+
only: true,
167+
errors: [
168+
{
169+
messageId: 'interactionShouldBeAwaited',
170+
data: { method: 'toHaveBeenCalled' },
171+
suggestions: [
172+
{
173+
messageId: 'fixSuggestion',
174+
output: dedent`
175+
import { expect, findByText } from '@storybook/test'
176+
WithModalOpen.play = async ({ args }) => {
177+
// should complain
178+
await expect(args.onClick).toHaveBeenCalled()
179+
const element = findByText(canvasElement, 'asdf')
180+
}
181+
`,
182+
},
183+
],
184+
},
185+
{
186+
messageId: 'interactionShouldBeAwaited',
187+
data: { method: 'findByText' },
188+
suggestions: [
189+
{
190+
messageId: 'fixSuggestion',
191+
output: dedent`
192+
import { expect, findByText } from '@storybook/test'
193+
WithModalOpen.play = async ({ args }) => {
194+
// should complain
195+
expect(args.onClick).toHaveBeenCalled()
196+
const element = await findByText(canvasElement, 'asdf')
197+
}
198+
`,
199+
},
200+
],
201+
},
202+
],
203+
},
149204
{
150205
code: dedent`
151206
WithModalOpen.play = ({ canvasElement }) => {

0 commit comments

Comments
 (0)