From 348dca40af2a126b03487ca26fd6d0887905b8e8 Mon Sep 17 00:00:00 2001 From: "Serhii [boonya] Buinytskyi" <779184+boonya@users.noreply.github.com> Date: Tue, 19 Sep 2023 00:48:20 +0200 Subject: [PATCH 1/2] Test cases first --- tests/lib/rules/await-interactions.test.ts | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/lib/rules/await-interactions.test.ts b/tests/lib/rules/await-interactions.test.ts index 3e21255..bf969ef 100644 --- a/tests/lib/rules/await-interactions.test.ts +++ b/tests/lib/rules/await-interactions.test.ts @@ -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: [ { @@ -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' }, + }, + ], + }, ], }) From 9a8fdb56de046c98a6c0afeeaface60e003be906 Mon Sep 17 00:00:00 2001 From: "Serhii [boonya] Buinytskyi" <779184+boonya@users.noreply.github.com> Date: Tue, 19 Sep 2023 01:09:36 +0200 Subject: [PATCH 2/2] There is no need to wait for the result of the call of userEvent.setup() statement. --- lib/rules/await-interactions.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/rules/await-interactions.ts b/lib/rules/await-interactions.ts index d546250..9073721 100644 --- a/lib/rules/await-interactions.ts +++ b/lib/rules/await-interactions.ts @@ -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) &&