当我指定相对路径时,我遇到了无法找到测试组件的模块错误。下面分享了配置细节。任何指针都会有帮助
Jest.config.js
module.exports = {
moduleNameMapper: {
'@core/(.*)': '<rootDir>/src/app/$1',
},
moduleDirectories: ["node_modules", "src"],
moduleFileExtensions: [
"js",
"jsx",
"ts",
],
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
collectCoverage:true,
coverageReporters: ['lcov', 'text', 'teamcity'],
collectCoverageFrom: [
"src/**/**/*.service.ts",
"src/**/**/**/*.component.ts",
"!<rootDir>/node_modules/",
"!<rootDir>/path/to/dir/"
]
};
样本类
/* import { ValidateComponent,} from '@thirdparty/some-components; */ this is working
import { ValidateComponent,} from '@thirdparty/some-components/lib/components/form/validate/validate.component';
ts-config.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom",
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableIvy": false
}
}