cypress-testing-library icon indicating copy to clipboard operation
cypress-testing-library copied to clipboard

@testing-library/cypress causes non-cypress tests to fail

Open OVO-Josh opened this issue 2 years ago • 1 comments

  • cypress-testing-library version: 9.0.0 (but also tested back to 6.0.7)
  • node version: 18.9.0
  • npm (or yarn) version: yarn v1.22.19

Relevant code or config


What you did:

After installing @testing-library/cypress, multiple unit tests written in @testing-library/react started to break.

What happened:

Prior to installing, the following unit test worked:


test("Add buy request and remove buy request buttons work", async () => {
  const user = userEvent.setup();
  render(<NewTradePage />);
  await user.click(screen.getAllByText("Add Buy Request")[0]);
  expect(screen.getByText("Requested Buy Volume 2")).toBeInTheDocument();
  await user.click(screen.getAllByText("Remove Buy Request")[0]);
  expect(screen.queryByText(/Requested Buy Volume 2 (MWh)/)).toBeNull();
});

After installing, I get the following error


TestingLibraryElementError: Unable to find an element with the text: Requested Buy Volume 2.

Suggested Solution:

I'm guessing this is due to @testing-library/react requiring version 8.5 of @testing-library/dom, whereas @testing-library/cypress requires version 8.1 - so maybe bumping the dependencies of the library?

OVO-Josh avatar Jan 27 '23 11:01 OVO-Josh