我正在尝试运行我的测试,但由于某些原因,我在执行npm run test时出现以下错误。
● Test suite failed to run
Cannot find module 'setupDevtools' from 'setup.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:229:17)
at Object.<anonymous> (node_modules/react-native/jest/setup.js:9:6)这是我的package.json
{
"private": true,
"name": "app",
"version": "0.1.0",
"scripts": {
"start": "react-native start",
"test": "jest",
"test:watch": "jest -w",
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"base-64": "^0.1.0",
"date-fns": "^2.0.0-alpha.8",
"hoist-non-react-statics": "^2.5.5",
"react": "16.3.1",
"react-native": "^0.55.4",
},
"devDependencies": {
"babel-eslint": "^8.2.3",
"babel-jest": "^24.7.1",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.8.2",
"flow-bin": "^0.97.0",
"flow-typed": "^2.5.1",
"jest": "^24.7.1",
"jest-react-native": "^18.0.0",
"prettier": "^1.12.1",
"react-devtools": "^3.2.2",
"react-native-testing-library": "^1.7.0",
"react-test-renderer": "16.3.1"
}
}发布于 2019-06-11 16:48:52
问题是我的依赖项上的版本不匹配。因为我使用了
"react": "16.3.1",
"react-native": "^0.55.4"我不得不从"jest": "^24.7.1"降级到"jest": "23.6.0"。在那之后,babel出现了一些问题。已安装"@babel/core": "^7.4.5"和"@babel/runtime": "^7.4.5"。并最终完成安装"babel-jest": "^24.8.0", "@testing-library/jest-native": "^3.0.1" and "native-testing-library": "^3.1.1",的整个过程
带有react-native@0.55.4的最终package.json
..omitted_code
"@babel/core": "^7.4.5",
"babel-jest": "^24.8.0",
"@babel/runtime": "^7.4.5",
"jest": "23.6.0",
"@testing-library/jest-native": "^3.0.1",
"native-testing-library": "^3.1.1",
..omitted_codehttps://stackoverflow.com/questions/56128597
复制相似问题