我正在尝试使用 ReactTestUtils 为react本机项目设置单元测试但是我在运行 npm test 时收到此错误:
Cannot find module 'react/lib/React' from 'ReactTestUtils.js'
我感觉我的依赖项不能正常工作,但我找不到原因。我已经尝试过降级 react 版本,但这并不能解决我的问题并调整 react-dom 版本,但我似乎无法找到黄金组合。
有谁知道这是否是一个已知问题?我无法在这里找到任何关于此的文档,在 react 文档中也找不到。
这是我的 package.json 配置:
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest --watch"
},
"dependencies": {
"react-native-scripts": "0.0.40",
"expo": "18.0.3",
"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-navigation": "1.0.0-beta.11"
},
"devDependencies": {
"enzyme": "^2.9.1",
"jest": "19.0.2",
"jest-expo": "~18.0.0",
"react-addons-test-utils": "^15.6.0",
"react-dom": "^15.6.1",
"react-test-renderer": "^16.0.0-alpha.12"
},
"jest": {
"preset": "react-native",
"collectCoverage": true,
"coverageDirectory": "__coverage__",
"testRegex": "./__tests__/[^setup].*.js$",
"transformIgnorePatterns": [
"node_modules/(?!react-native|native-base|react-navigation|react-native-fabric)"
],
"setupFiles": [
"./__tests__/setup.js"
]
}