Skip to content

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

Closed
@dfernandez79

Description

@dfernandez79

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions