Skip to content

Commit

Permalink
Merge pull request #87 from VinceMalone/fix-await-interaction-chain-e…
Browse files Browse the repository at this point in the history
…xpression

fix: support ChainExpression in await-interactions rule
  • Loading branch information
yannbf authored Apr 15, 2022
2 parents 3136960 + 1128ceb commit ce04910
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/await-interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export = createStorybookRule({
return {
CallExpression(node: CallExpression) {
const method = getMethodThatShouldBeAwaited(node)
if (method && !isAwaitExpression(node.parent)) {
if (method && !isAwaitExpression(node.parent) && !isAwaitExpression(node.parent?.parent)) {
invocationsThatShouldBeAwaited.push({ node, method })
}
},
Expand Down
31 changes: 29 additions & 2 deletions tests/lib/rules/await-interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ ruleTester.run('await-interactions', rule, {
// `,
'Basic.play = async () => userEvent.click(button)',
'Basic.play = async () => { return userEvent.click(button) }',
dedent`
export const SecondStory = {
play: async (context) => {
await FirstStory.play(context)
}
}
`,
dedent`
export const SecondStory = {
play: async (context) => {
await FirstStory.play?.(context)
}
}
`,
dedent`
export const SecondStory = {
play: async (context) => {
await FirstStory.play!(context)
}
}
`,
],
invalid: [
{
Expand Down Expand Up @@ -292,18 +313,20 @@ ruleTester.run('await-interactions', rule, {
},
{
code: dedent`
export const ThirdStory = {
export const FourthStory = {
play: async (context) => {
FirstStory.play(context)
SecondStory.play!(context)
ThirdStory.play?.(context)
}
}
`,
output: dedent`
export const ThirdStory = {
export const FourthStory = {
play: async (context) => {
await FirstStory.play(context)
await SecondStory.play!(context)
await ThirdStory.play?.(context)
}
}
`,
Expand All @@ -316,6 +339,10 @@ ruleTester.run('await-interactions', rule, {
messageId: 'interactionShouldBeAwaited',
data: { method: 'play' },
},
{
messageId: 'interactionShouldBeAwaited',
data: { method: 'play' },
},
],
},
],
Expand Down

0 comments on commit ce04910

Please sign in to comment.