我有一个问题。当我运行 Jest 测试时,它无法解析带有 at (@
) 符号的导入。我有一个错误:
FAIL src/App.test.js
● Test suite failed to run
Cannot find module '@/helpers/configureStore' from 'App.js'
如何解决此错误?
最佳答案
我找到了解决方案in this post 。所以根据jest docs我们应该去我们的package.json
文件,并确保我们的配置包含类似以下内容:
{
"jest": {
"moduleNameMapper": {
"@/(.*)$": "<rootDir>/src/$1"
}
}
}
"@/(.*)$": "<rootDir>/src/$1"
这是一个很酷的正则表达式,它将解决我们的 @/helpers/configureStore
至src/helpers/configureStore
.
另请记住退出jest交互模式(使用 q
键)并再次运行以查看更改。
关于javascript - Jest 无法解析带有 @ (at) 字符的导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55400845/