jest-dom icon indicating copy to clipboard operation
jest-dom copied to clipboard

`TypeError: element.getRootNode is not a function` when using `toBeVisible` or `toBeInTheDocument`

Open milkshakeuk opened this issue 3 years ago • 0 comments

  • @testing-library/jest-dom version: any version since 5.11.10
  • node version: 16.15.0
  • npm version: 7.2.0
  • aurelia-testing version: 1.1.0

Relevant code or config:

We are using the default jest testEnvironment of node.

...
const readOnlyTitle = component.querySelector("[data-spec=rtr-read-only-title]")
expect(readOnlyTitle).toBeVisible();

What you did:

upgrading jest-dom dependency from 5.11.0 to 5.16.4

What happened:

existing passing tests broke.

image

Reproduction:

Problem description:

Upgrading a minor version shouldn't break existing APIs.

Suggested solution:

Make sure the implementation of toBeVisible and toBeInTheDocument work with jest-environment-node and jest-environment-jsdom not just jest-environment-jsdom.

It seems the usage of element.getRootNode in toBeVisible and toBeInTheDocument does not work when using jest-environment-node.

Is there a way to change the implementation so that it works in both environments?

milkshakeuk avatar May 18 '22 10:05 milkshakeuk