dom-testing-library: Doesn't work with custom jsdom

  • dom-testing-library version: 3.5.1
  • react version: 16.4.1
  • node version: 10.4.1
  • npm (or yarn) version: yarn 1.7.0

Relevant code or config:

Usual installation,

"testEnvironment": "node",

as jest configuration, then something like following in tests:

import { getByText } from 'dom-testing-library'

it('Suggests cities to search by', async () => {
  const container = createJSDOM(...)
  getByText(container, 'foobar')
})

What you did:

Tried to use dom-testing-library with node environment in Jest + creating own jsdom instance in a helper and passing it to dom-testing-library.

What happened:

● Test suite failed to run

ReferenceError: window is not defined

  at Object.<anonymous> (node_modules/mutationobserver-shim/dist/mutationobserver.min.js:3:1)
  at Object.<anonymous> (node_modules/dom-testing-library/dist/wait-for-element.js:8:1)
  at Object.<anonymous> (node_modules/dom-testing-library/dist/index.js:32:23)

Reproduction:

As above, enable node jest environment and try to use dom-testing-library with some custom container

Suggested solution:

check if shim is loaded on given container and install it only then? generally something to support no global window object in jest environment

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 22 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not going to argue about this with you. I’m going to set a lightweight test in place so we hopefully don’t break things in the future. If that’s no enough for you then feel free to use an old version of the library or maintain a fork.