Skip to content

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

Open
@ahce

Description

@ahce

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

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