I'm trying to get Jest to run a snapshot test of my React app. The versions from my package.json:
"react": "15.6.1",
"react-dom": "15.6.1",
"react-test-renderer": "15.6.1",
I can't get past this error:
● Test suite failed to run
Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (node_modules/react-test-renderer/lib/ReactDebugTool.js:16:30)
I have tried removing and reinstalling my node_modules dir and I've verified that the path to my component is correct but still get this same error.
My test looks like this:
import React from 'react';
import renderer from 'react-test-renderer';
import { Section } from '../../app/views/containers/section';
it('renders correctly', () => {
const section = renderer.create(
<Section key="1" section="finance"/>
).toJSON();
expect(section).toMatchSnapshot();
});
What am I doing wrong?
Ran into the similar problem last week, we have a React-Native project that has recently upgraded to:
"react-native": "0.45.1"
"react": "16.0.0-alpha.12"
"jest": "20.0.4"
"react-test-renderer": "15.5.4"
and then we try to run our Jest tests and we saw the same issue as you mentioned above. Then we realized there is a cutting edge version of the react-test-renderer and we tried that one out:
"react-test-renderer": "^16.0.0-alpha.12"
,
And now the issue is no longer there.
On 0.47.0
Still had errors with the accepted answer had to do the following:
"react-dom": "^16.0.0-beta.5",
"react-test-renderer": "16.0.0-alpha.12",
enzyme will work with the above changes but any sort of simulation will not, disabled taps until they support.
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