我正在为我的 Web 应用程序设置测试,该应用程序使用 Vue 框架与 TypeScript,并使用 Jest 框架。除了带有 @
符号的导入(例如 import { Foo } from '@/bar'
)之外,一切似乎都可以正常工作。无论它出现在我的测试文件还是源代码中,它都不能理解并返回以下结果:
Cannot find module '@/store' from 'src/tests/foo.spec.ts'
这是我的 Jest 配置文件,位于 package.json
中:
"jest": {
"moduleFileExtensions": [
"js",
"ts",
"json",
"vue"
],
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"transform": {
".*\\.(vue)$": "vue-jest",
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
},
"testURL": "http://localhost/",
"collectCoverage": true,
"collectCoverageFrom": ["**/*.{ts,vue}", "!**/node_modules/**"],
"coverageReporters": ["html", "text-summary"]
}
有人知道如何使其正常工作吗?
谢谢。