在 Jest 中使用绝对路径 [英] Use absolute paths with Jest
本文介绍了在 Jest 中使用绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 create-react-app 创建了一个应用.
我在 .env 中设置了我的 NODE_PATH=src/
当我启动 react-script start 时一切正常,但是当我启动 react-script test 时出现错误:未找到导入.在我的 package.json 中:
I have create an app with create-react-app.
I have set in .env my NODE_PATH=src/
All works fine when I launch react-script start but when I launch react-script test I have an error: import is not found.
In my package.json :
"test": "jest --colors --coverage test"
编辑
它适用于:
"jest": {
"modulePaths": ["src/"],
"testURL": "http://localhost",
"jest": "^22.4.4"
}
推荐答案
如果你想直接调用 jest
而不是使用 react-scripts
中的捆绑集,你有打电话:
If you want to directly call jest
instead using the bundling set in react-scripts
, you have to call:
"test": "./node_modules/jest/bin/jest.js --colors --coverage test"
这篇关于在 Jest 中使用绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文