I'd like to use enzyme to test my React-Native components in Expo managed project. I follow the docs for jest-expo-enzyme, but now I get:
Test environment found at "/Users/raarts/myproject/node_modules/jest-environment-enzyme/lib/index.js" does not export a "getVmContext" method, which is mandatory from Jest 27. This method is a replacement for "runScript".
My guess from here is that jest-environment-enzyme
(last release 2 years ago), somehow needs to be updated for jest 27, but given jest-expo-enzyme
was released 2 months ago, I figured I must be doing something wrong. Clueless on how to proceed.
Anybody has any advice?
This is a bug in enzyme. A workaround is provided in this comment.
The solution is to force upgrade jest-environment-jsdom
package.
The better way to do it is via resolutions, if you are using Yarn, add this to your package.json:
"resolutions": {
"jest-environment-jsdom": "27.4.6"
},
Check for the latest version of jest-environment-jsdom and change it if necessary.
You can also do this in classic NPM using the npm-force-resolutions package.
Note: you may encounter other problems after fixing this one, if you get a setImmediate
error see this comment
I am working on Next js project and using Jest and enzyme for testing, and for me I was able to fix this error by changing testEnvironment: 'enzyme', to testEnvironment: 'jsdom', in jest.config.js file.
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