开玩笑无法从'setup.js'中找到模块'setupDevtools' [英] Jest Cannot find module 'setupDevtools' from 'setup.js'
问题描述
Jest是我的React/Redux应用程序测试套件的新手,由于此错误困扰我的应用程序,我无法运行actions
测试:
New to Jest as my testing suite for a React / Redux application and I am unable to run my actions
tests due to this error plaguing my application:
测试套件无法运行
无法从'setup.js'中找到模块'setupDevtools'
在Resolver.resolveModule(node_modules/jest-resolve/build/index.js:191:17)
at对象. (node_modules/react-native/jest/setup.js:30:1)
从测试文件中删除所有内容会产生相同的错误.这是我的Jest配置:
Removing all content from my test file produces the same error. Here is my Jest config:
"jest": {
"verbose": true,
"preset": "jest-react-native",
"roots": [
"<rootDir>/src/actions/_tests_"
]
}
这是我的依赖项:
"dependencies": {
"dotenv": "^4.0.0",
"fhirclient": "^0.1.12",
"full-age-calculator": "0.0.4",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"verror": "^1.10.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.7",
"eslint": "^4.12.1",
"eslint-config-cerner": "^1.0.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.5.1",
"html-webpack-plugin": "^2.30.1",
"jest": "^21.2.1",
"jest-react-native": "^18.0.0",
"node-sass": "^4.7.2",
"react-native": "^0.51.0",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.0",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.5"
},
我尝试了此Github问题页面中的一些建议,但没有解决我的问题.
I tried a few of the suggestions from this Github issue page which did not resolve my issue.
推荐答案
我今天重新开始并解决了自己的问题.事实证明,Babel有文档,其中专门说明了如何设置Jest.总之,这是我的工作:
I started anew today and solved my own problem. As it turns out, Babel has documentation which specifically explains how to setup Jest. In summary, here's what I did:
安装NPM模块
npm install --save-dev babel-jest
npm install --save-dev babel-preset-env
或使用一个命令:
npm install i -d babel-jest babel-preset-env
创建.babelrc配置文件
{
"presets": ["env"]
}
修改package.json
{
"scripts": {
"test": "jest"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
}
}
以下是进一步阅读的内容,说明了为什么需要env preset
配置.编码愉快!
Here is some further reading on why the env preset
configuration is needed. Happy coding!
这篇关于开玩笑无法从'setup.js'中找到模块'setupDevtools'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!