testing-library/eslint-plugin-testing-library

`no-unnecessary-act`: Doesn't report when the variable has a name other than "userEvent"

ahce opened this issue · 3 comments

ahce commented

Have you read the Troubleshooting section?

Yes

Plugin version

5.10.3

ESLint version

8.39.0

Node.js version

16.20.0

package manager and version

8.19.4

Operating system

macOS Ventura, version 13.2.1

Bug description

In the documentation, the examples named userEvent as "user".

When the variable has been named as "user" the no-unnecessary-act doesn't report.

Steps to reproduce

const { screen, act } = require('@testing-library/react');
const { default: userEventRoot } = require('@testing-library/user-event');

test('no-unnecessary-act no report with other root name', async () => {
  await act(async () => {
    await userEventRoot.click(
      screen.getByRole('button', { name: /click me!/i }),
    );
  });
});
test('no-unnecessary-act no report with setup', async () => {
  const user = userEventRoot.setup();

  await act(async () => {
    await user.click(screen.getByRole('button', { name: /click me!/i }));
  });
});
test('no-unnecessary-act report ok', async () => {
  const userEvent = userEventRoot.setup();

  await act(async () => {
    await userEvent.click(screen.getByRole('button', { name: /click me!/i }));
  });
});

Error output/screenshots

imagen

ESLint configuration

{
  "root": true,
  "extends": ["airbnb", "plugin:testing-library/react"],
  "env": {
    "jest": true
  }
}

Rule(s) affected

no-unnecessary-act

Anything else?

No response

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

No

Thanks for reporting @ahce. This is probably caused by the default import being renamed. That could potentially prevent every rule in the repo to report errors properly, so it's a core change to the plugin.