Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dfernandez79 opened this issue Sep 25, 2023 · 4 comments · Fixed by #834
Labels
bug Something isn't working

Comments

@dfernandez79
Copy link

dfernandez79 commented Sep 25, 2023

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

@dfernandez79 dfernandez79 added bug Something isn't working triage Pending to be triaged by a maintainer labels Sep 25, 2023
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Sep 26, 2023
@shoota
Copy link

shoota commented Sep 27, 2023

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

@sidrak19
Copy link

sidrak19 commented Oct 5, 2023

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

@trungutt
Copy link

trungutt commented Nov 9, 2023

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

@Belco90 Belco90 linked a pull request Nov 9, 2023 that will close this issue
1 task
@Belco90
Copy link
Member

Belco90 commented Nov 9, 2023

Done. This should be fixed in v6.1.2.

@Belco90 Belco90 closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants