react typescript testing TypeError: MutationObserver is not a constructor

Are you running latest CRA? If so then this issue https://github.com/facebook/create-react-app/pull/8362 might be what you're experiencing. That's solvable by installing https://www.npmjs.com/package/jest-environment-jsdom-sixteen, e.g. $ yarn add -D jest-environment-jsdom-sixteen and editing your test script:

 ...
  "scripts": {
    ...
-   "test": "react-scripts test --env=dom"
+   "test": "react-scripts test --env=jest-environment-jsdom-sixteen"
    ...
  },
  ...
  "devDependencies": {
    ...
    "jest-environment-jsdom-sixteen": "^1.0.3",
    ...
  },
  ...

Essentially you will tell your jest to use jsdom v16 instead of v15(default for Jest v25).


I also faced the same issue.

Before trying the accepted answer, I updated react-scripts to version 4.0.1.

That solved the issue, because react-scripts 4.0.1 uses Jest 26.6.x.

Therefore, try upgrading react-scripts first.