0

We recently updated some of our project dependencies and one of them was jest-dom, we went from v5.11.0 to v5.16.4. As of v5.11.10 they introduced a new condition to the toBeVisible method so that the element had to be in the document, as part of this check its implementation calls element.getRootNode.

Since this change, our tests which use toBeVisible now fail with the following message:

TypeError: element.getRootNode is not a function

I suspect that using node as the Jest testEnvironment is the issue and that for whatever reason the Node implementation doesn't have getRootNode and it probably should.

Is there a way round this (without changing the test environment to jsdom, since that causes loads of tests to break)?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Jake Aitchison
  • 1,079
  • 6
  • 20
  • _"the `node` implementation doesn't have `getRootNode` and it probably should"_ - _why_ should it? That's a web API. – jonrsharpe May 18 '22 at 09:58
  • so that you can use `jest-dom` assertions? since the default `testEnvironment` for jest is `node` why would `jest-dom` implement something that doesn't work in both environments? – Jake Aitchison May 18 '22 at 10:00
  • `jest-dom` is a third-party library, it's certainly not the case that even the core Jest test environments must support every possible assertion utility. The default test environment doesn't provide _any_ of the web APIs, because it's just Node. – jonrsharpe May 18 '22 at 10:29
  • @jonrsharpe this does make sense, I have raised [this issue](https://github.com/testing-library/jest-dom/issues/458) on their GitHub. – Jake Aitchison May 18 '22 at 11:06

0 Answers0