[英]Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js'
I'm trying to get Jest to run a snapshot test of my React app.我试图让 Jest 运行我的 React 应用程序的快照测试。 The versions from my package.json:我的 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.我已经尝试删除并重新安装我的 node_modules 目录,并且我已经验证了我的组件的路径是正确的,但仍然得到同样的错误。
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项目:
"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. 然后我们尝试运行我们的Jest测试,我们看到了与上面提到的相同的问题。 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"
, "react-test-renderer": "^16.0.0-alpha.12"
,
And now the issue is no longer there. 现在问题不再存在了。
On 0.47.0 在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. 酶将适用于上述变化,但任何类型的模拟都不会,禁用水龙头直到它们支持。
升级到React 16.0.0时,我确实注意到你确实需要将react-dom升级到16.0.0并且它完美无瑕!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.