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

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

Open
ahce opened this issue Apr 28, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ahce
Copy link

ahce commented Apr 28, 2023

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

@ahce ahce added bug Something isn't working triage Pending to be triaged by a maintainer labels Apr 28, 2023
@Belco90
Copy link
Member

Belco90 commented May 4, 2023

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.

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label May 4, 2023
@thkim1011
Copy link

thkim1011 commented Apr 23, 2024

@Belco90 I think this still happens even when the default import isn't renamed. For example, the following will not report a lint error.

import { act, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

describe("test", () => {
  it("this does not cause a lint error", async () => {
    const user = userEvent.setup();
    await act(() => user.click(screen.getByText("Test")));
  });

  it("this does cause a lint error", async () => {
    await act(() => userEvent.click(screen.getByText("Test")));
  });
});

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
Development

No branches or pull requests

3 participants