Skip to content

Doesn't work with custom jsdom #100

@sheerun

Description

@sheerun
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions