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

The findByRole function in react testing library is failing in some tests. #1302

Open
hirakazuuu opened this issue Mar 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@hirakazuuu
Copy link

The findByRole function in react testing library is failing in some tests.

Triggering Condition:
The issue started occurring after the update to version 13.7.1 of happy-dom.

Versions of OSS Used:

"happy-dom": "13.7.1"
"msw": "2.2.3"
"vitest": "1.3.1"
"@testing-library/react": "^14.2.1"

Failing Test Example:

it("dialog", async () => {
  render(
    <RouteErrorProvider>
      <CustomFields {...initialProps} />
    </RouteErrorProvider>,
  );
  const heading = await screen.findByRole("heading", { name: "field" });
  await waitFor(() => expect(heading).toBeInTheDocument());
  fireEvent.click(screen.getByRole("button", { name: "edit button" }));
  const editDialog = await screen.findByRole("dialog", { name: "edit fields" });
  expect(editDialog).toBeInTheDocument();
  const input = within(editDialog).getByLabelText("label text");
  fireEvent.change(input, { target: { value: "new text" } });
  fireEvent.click(screen.getByRole("button", { name: "button name" }));

  // The error occurs here
  const confirmDialog = await screen.findByRole("dialog", { name: "confirm dialog" });
  expect(confirmDialog).toBeInTheDocument();
});

Your cooperation in resolving this issue is greatly appreciated.

@hirakazuuu hirakazuuu added the bug Something isn't working label Mar 13, 2024
@capricorn86
Copy link
Owner

Possible duplicate of #1122

@capricorn86
Copy link
Owner

capricorn86 commented Mar 14, 2024

Thank you for reporting @hirakazuuu! 🙂

I have made a fix for #1122, which may be a duplicate of this issue.

Can you please test if the fix in v13.8.5 of Happy DOM solved your issue?

If it didn't solve the issue, can you please setup a reproducible example in Stackblitz or similar? It is otherwise hard to debug why it is failing for you.

@x7ddf74479jn5
Copy link

@capricorn86
I'm a colleague of @hirakazuuu.
Our issue was resolved with the fix in v13.10.1.
Thank you very much.

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