eslint-plugin-storybook icon indicating copy to clipboard operation
eslint-plugin-storybook copied to clipboard

await-interactions false positive in case of userEvent.setup function suggested by v14 api

Open boonya opened this issue 2 years ago • 5 comments

Describe the bug

Latest version of user-event lib recommends to use a little bit different API. Instead of using userEvent.click they suggest to create user-event instance first by invoking const events = userEvent.setup(). And then use any event available e.g. await events.click(). userEvent.setup returns an object directly without promise, so it shouldn't be awaiten. But the rule "storybook/await-interactions" reports an issue there.

To Reproduce

  1. Install latest version of @storybook/testing-library (0.2.0 in my case)
  2. Import userEvent constructor.
  3. Define play function to any story you need.
  4. Declare userEvent.setup(); statement as it recommended in latest user-event section.
  5. See the validation error.

Expected behavior Validation error should not be triggered on setup method.

Screenshots image

boonya avatar Jul 10 '23 16:07 boonya

Hey @boonya thanks a lot for flagging this! Would you be open to making a PR that fixes it? Thanks!

yannbf avatar Jul 16 '23 16:07 yannbf

Hey @boonya thanks a lot for flagging this! Would you be open to making a PR that fixes it? Thanks!

With pleasure... When I have a time and inspiration ;)

boonya avatar Jul 19 '23 08:07 boonya

I tried to work on this issue, but I was frustrated because I am new to eslint plugin development. The existing API determines the userEvent object by its name, so I couldn't figure out how to determine the variable created in userEvent.setup. I'll try some more when I have time, but I'd be happy if there were contributions from experts until then.

moeyashi avatar Sep 08 '23 04:09 moeyashi

This is what I have so far https://github.com/storybookjs/eslint-plugin-storybook/pull/142 But I am a little bit stuck, caue I don't see how to integrate expectation of await before the variable created by userEvent.setup(). I'll try a bit later, but may be someone has some suggestion or idea.

boonya avatar Sep 25 '23 05:09 boonya

Looks like this is something related https://github.com/testing-library/eslint-plugin-testing-library/pull/817

boonya avatar Sep 29 '23 12:09 boonya