Skip to content

MutationObserver is not a constructor #662

@danielkcz

Description

@danielkcz
  • @testing-library/react version: 10.0.4
  • react version: 16.12.0

Relevant code or config:

import { render, screen, fireEvent } from '@testing-library/react'

test('works?', async () => {
  render(<App />)
  const elem = await screen.findByText('TEST')
  fireEvent.click(elem)
})

What you did:

Run the test :)

What happened:

image

Reproduction:

https://codesandbox.io/s/practical-colden-jbnzf?file=/src/App.test.js

It actually works there, because MutationObserver is available in a browser, but apparently not in jsdom

Problem description:

It's not documented anywhere that MutationObserver would need to be polyfilled. Either way, after doing the following, problem is workaround-ed :)

window.MutationObserver = require("mutation-observer");

Suggested solution:

I think polyfill should be part of the library to remove the hassle of users doing that.

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