I'm trying to mount a component for testing with enzyme, and get this error.
A few days ago, React released version 18, which is not compatible with Enzyme. Furthermore, it probably is not achievable to use Enzyme with React 18. If you're still using Enzyme, it is time to look into alternatives. The most popular option besides Enzyme seems to be React Testing Library.
npm install --save-dev --save-exact jsdom jsdom-global
Then:
import 'jsdom-global/register'; //at the top of file, even before importing React
More info here.
Alternative: In case you are using jest with enzyme-
In your package.json
, specify the test environment for jest as jsdom
as follows:
"jest": {
"testEnvironment": "jsdom"
}
I faced the same issue and it worked well for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With