testing-library/eslint-plugin-testing-library

`await-async-events` reports a problem when `userEvent.setup` is called from another function

dfernandez79 opened this issue ยท 4 comments

Have you read the Troubleshooting section?

Yes

Plugin version

v6.0.2

ESLint version

v8.50.0

Node.js version

18.18.0

package manager and version

npm 9.8.1

Operating system

macOS Ventura 13.5.2 (22G91)

Bug description

The rule await-async-events with Promise returned from setUpUserEvents wrapper over async event method must be handled when I call userEvent.setup() from setUpUserEvents.

Example:

import userEvent, { type UserEvent } from '@testing-library/user-event';

const setUpUserEvents = (): UserEvent =>
  userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

test('Something', async () => {
  const { click } = setUpUserEvents();

  /* ... */
  await click(someElement);
});

Steps to reproduce

  1. Create a test that uses userEvent.setup()
  2. Run lint w/await-async-events (all ok)
  3. Refactor the call to userEvent.setup() into another function
  4. Run lint w/await-async-events (eslint fails)

Error output/screenshots

Before the refactor:
image

After the refactor (eslint error):
image

image

Eslint error:

error  Promise returned from `setUpUserEvents` wrapper over async event method must be handled  testing-library/await-async-events

ESLint configuration

I'm extending AirBnb rules with:

    {
      files: ['**/*.test.ts?(x)'],
      env: {
        jest: true,
      },
      extends: ['plugin:testing-library/react', 'plugin:jest-dom/recommended'],
    },

Rule(s) affected

testing-library/await-async-events

Anything else?

The PR #817 is checking for the name setup.

Maybe that isn't enough.

Do you want to submit a pull request to fix this bug?

No

we have same problem like below in v6.0.2

const setup = () => {
  const utils = render(<SomeComponent />,);
  const user = userEvent.setup();  // error, `Promise returned from async event method `user` must be handled`

  return { ...utils, user};
};


...

describe('test suit', () => {
  it('case', async () => {
    const user = userEvent.setup();  // no error

We are getting a similar issue to what @shoota mentioned above, is there any different way/fix for doing this?

A fix was merged into main. @Belco90 could you please make a release? That will make a lot of folks happy ๐Ÿ™‡

Done. This should be fixed in v6.1.2.