Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDom does not mock window.MutationObserver. #6617

Closed
deskoh opened this issue Mar 11, 2019 · 2 comments
Closed

JSDom does not mock window.MutationObserver. #6617

deskoh opened this issue Mar 11, 2019 · 2 comments

Comments

@deskoh
Copy link

deskoh commented Mar 11, 2019

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Yes.

Which terms did you search for in User Guide?

jsdom
testing

Environment

Environment Info:

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz
  Binaries:
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 44.17763.1.0
    Internet Explorer: 11.0.17763.1
  npmPackages:
    react: ^16.8.4 => 16.8.4
    react-dom: ^16.8.4 => 16.8.4
    react-scripts: 2.1.8 => 2.1.8
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. create-react-app jsdom-test
  2. Add expect(window.MutationObserver).not.toBeUndefined(); to generated App.test.js.
  3. Run npm run test.

Expected Behavior

npm run test should pass as window.MutationObserver should be defined by jsdom as tested using the following code:

// Mock DOM (https://airbnb.io/enzyme/docs/guides/jsdom.html)
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

const assert = require('assert');

assert(window.MutationObserver);

Actual Behavior

Test fails as window.MutationObserver is undefined.

  ● test MutationObserver

    expect(received).not.toBeUndefined()

    Received: undefined
@ianschmitz
Copy link
Contributor

It looks like this was recently merged into jsdom: jsdom/jsdom#2398. We will have to wait until jest bumps their version of jsdom.

There is nothing we can do on our end until Jest gets updated. Until then i recommend you try mocking it out yourself to get things going.

@lock lock bot locked and limited conversation to collaborators Mar 16, 2019
@ianschmitz
Copy link
Contributor

Just a heads up that we're working on updating to jsdom@14 which includes MutationObserver for create-react-app v3. You can follow the progress at #6654.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants