[英]Imports not working in Jest that start with @
I recently joined a team of developers to work on their webapp.我最近加入了一个开发团队来开发他们的 webapp。 I am writing tests for it and most of their files use
@ imports
instead of writing the filepath in the format of ../../我正在为它编写测试,他们的大部分文件都使用
@ imports
而不是以 ../../ 格式编写文件路径
When trying to write tests in Jest for these I am unable to import and keep getting this error尝试在 Jest 中为这些编写测试时,我无法导入并不断收到此错误
Cannot find module '@util/helpers.js' from '_controller.js'
Is there a way I can configure jest to accept @ based imports?有没有办法可以配置 jest 来接受基于 @ 的导入? I have looked long and hard online and so far have not been able to find any solution that works.
我在网上看了很长时间,到目前为止还没有找到任何有效的解决方案。
Adding this to module name mapper fixed it将此添加到模块名称映射器修复它
"moduleNameMapper": {
"^@util(.*)$": "<rootDir>/src/util$1",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.