react-native - 尝试在反应本机应用程序上运行 jest 时测试失败。找不到“setupDevtools”错误
问题描述
我正在尝试运行我的测试,但由于某种原因,我在执行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"
}
}
解决方案
问题在于我的依赖项的版本不匹配。由于我正在使用
"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",
最后package.json
与react-native@0.55.4
..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_code
推荐阅读
- javascript - `export Module from "module"` 是有效的 JavaScript 语法吗?
- javascript - For 和 MailApp 的问题
- ruby - Pusher 无法建立连接
- php - 如何生成发送到电子邮件的自动编号
- firebase - 确定嵌套子集合的 Firebase 读取次数
- amazon-dynamodb - 基于 GSI 查询 DynamoDB
- javascript - 当导入的文件正在导入一个文件,而导入它的文件也在导入该文件时会发生什么?
- swift - Xcode Beta 6“没有更多上下文的表达式类型不明确”导航链接
- angular - scrollablePlotArea 和向下钻取按钮位置
- c - 在线裁判中的错误答案 (CODECHEF)