capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.24k stars 194 forks source link

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

Open hirakazuuu opened 5 months ago

hirakazuuu commented 5 months ago

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.

capricorn86 commented 5 months ago

Possible duplicate of #1122

capricorn86 commented 5 months ago

Thank you for reporting @hirakazuuu! :slightly_smiling_face:

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 commented 4 months ago

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