storybookjs / eslint-plugin-storybook

🎗Official ESLint plugin for Storybook
MIT License
238 stars 42 forks source link

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

Open boonya opened 11 months ago

boonya commented 11 months ago

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

yannbf commented 11 months ago

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

boonya commented 11 months ago

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 ;)

moeyashi commented 9 months ago

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.

boonya commented 9 months ago

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 commented 9 months ago

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