tutorial
tutorial copied to clipboard
[STEP-9] TypeError: MutationObserver is not a constructor
I've tried to update outdated packages but it does not solved the problem
LOG
FAIL src/tests/app.js
✕ it shows a message when there are no reminders (67ms)
● it shows a message when there are no reminders
TypeError: MutationObserver is not a constructor
12 | visit("/")
> 13 | await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
| ^
14 |
15 | expect(screen.getByText("All done!")).toBeInTheDocument()
16 | })
at node_modules/@testing-library/dom/dist/wait-for.js:79:18
at waitFor (node_modules/@testing-library/dom/dist/wait-for.js:42:10)
at node_modules/@testing-library/dom/dist/wait-for.js:135:54
at node_modules/@testing-library/react/dist/pure.js:58:22
at node_modules/@testing-library/react/dist/act-compat.js:60:24
at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21856:12)
at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:929:14)
at node_modules/@testing-library/react/dist/act-compat.js:59:20
at asyncAct (node_modules/@testing-library/react/dist/act-compat.js:38:14)
at Object.asyncWrapper (node_modules/@testing-library/react/dist/pure.js:57:35)
at waitForWrapper (node_modules/@testing-library/dom/dist/wait-for.js:135:35)
at waitForElementToBeRemoved (node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js:39:31)
at Object.<anonymous> (src/tests/app.js:13:11)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.8s, estimated 2s
Ran all test suites.
Watch Usage: Press w to show more.
Whoops, sorry I missed this! Wasn't subscribed to the repo.
What version of node?
I've run into this before, maybe six months or so ago on another React project.
Issue iirc was jest's jsdom dependency does not have MutationObserver. I think maybe I just polyfilled it as a quickfix.
More info here: https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0
12.18.3
The solution for me was this one. I updated react-scripts to the latest version and it worked.
Installing the jest-environment-jsdom-sixteen
package and changing the test script worked for me, see issue
"test": "craco test --env=jest-environment-jsdom-sixteen",