【发布时间】:2018-11-01 07:02:56
【问题描述】:
tsconfig.json 的 paths 设置如下:
"paths": {
"@fs/*": ["src/*"],
"@test/*": ["test/*"]
}
所有 @fs/blah/blah 导入在 VSCode 中都可以正常解析。为了让 Jest 使用相同的导入声明,我将 moduleMapper 添加到 jest.config.ts,这是完整的配置:
module.exports = {
roots: ["./src"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"@fs/*": ["src/*"]
}
};
import { isBoolean } from "@fs/is"; 这样的语句无法解析。
当使用相对导入进行更改时,Jest 会解决它 (import { isBoolean } from "./is";)
想法?
【问题讨论】:
标签: javascript node.js typescript jestjs