JSDom does not mock window.MutationObserver.
Created by: deskoh
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
create-react-app jsdom-test
- Add
expect(window.MutationObserver).not.toBeUndefined();
to generatedApp.test.js
. - 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