我已经使用 create-react-app 创建了一个应用程序。
我已经在 .env 中设置了我的 NODE_PATH=src/
当我启动 react-script start 时一切正常,但是当我启动 react-script test 时出现错误:找不到导入。
在我的 package.json 中:
"test": "jest --colors --coverage test"
编辑
它适用于:
"jest": {
"modulePaths": ["src/"],
"testURL": "http://localhost",
"jest": "^22.4.4"
}
最佳答案
你应该执行你的测试
npm 测试
而不是在这里直接使用react-scripts
。 Jest 在使用由 create-react-app
创建的项目时自动配置。
关于javascript - 在 Jest 中使用绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51934521/