Skip to content

Commit ce04910

Browse files
authored
Merge pull request #87 from VinceMalone/fix-await-interaction-chain-expression
fix: support ChainExpression in await-interactions rule
2 parents 3136960 + 1128ceb commit ce04910

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/rules/await-interactions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export = createStorybookRule({
141141
return {
142142
CallExpression(node: CallExpression) {
143143
const method = getMethodThatShouldBeAwaited(node)
144-
if (method && !isAwaitExpression(node.parent)) {
144+
if (method && !isAwaitExpression(node.parent) && !isAwaitExpression(node.parent?.parent)) {
145145
invocationsThatShouldBeAwaited.push({ node, method })
146146
}
147147
},

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ ruleTester.run('await-interactions', rule, {
8080
// `,
8181
'Basic.play = async () => userEvent.click(button)',
8282
'Basic.play = async () => { return userEvent.click(button) }',
83+
dedent`
84+
export const SecondStory = {
85+
play: async (context) => {
86+
await FirstStory.play(context)
87+
}
88+
}
89+
`,
90+
dedent`
91+
export const SecondStory = {
92+
play: async (context) => {
93+
await FirstStory.play?.(context)
94+
}
95+
}
96+
`,
97+
dedent`
98+
export const SecondStory = {
99+
play: async (context) => {
100+
await FirstStory.play!(context)
101+
}
102+
}
103+
`,
83104
],
84105
invalid: [
85106
{
@@ -292,18 +313,20 @@ ruleTester.run('await-interactions', rule, {
292313
},
293314
{
294315
code: dedent`
295-
export const ThirdStory = {
316+
export const FourthStory = {
296317
play: async (context) => {
297318
FirstStory.play(context)
298319
SecondStory.play!(context)
320+
ThirdStory.play?.(context)
299321
}
300322
}
301323
`,
302324
output: dedent`
303-
export const ThirdStory = {
325+
export const FourthStory = {
304326
play: async (context) => {
305327
await FirstStory.play(context)
306328
await SecondStory.play!(context)
329+
await ThirdStory.play?.(context)
307330
}
308331
}
309332
`,
@@ -316,6 +339,10 @@ ruleTester.run('await-interactions', rule, {
316339
messageId: 'interactionShouldBeAwaited',
317340
data: { method: 'play' },
318341
},
342+
{
343+
messageId: 'interactionShouldBeAwaited',
344+
data: { method: 'play' },
345+
},
319346
],
320347
},
321348
],

0 commit comments

Comments
 (0)