[英]Error home.component.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property
When running ng test I get the following error home.component.spec.ts is missing from the TypeScript compilation.运行 ng test 时,TypeScript 编译中缺少以下错误 home.component.spec.ts。 Please make sure it is in your tsconfig via the 'files' or 'include' property.
请通过“文件”或“包含”属性确保它在您的 tsconfig 中。
Project structure项目结构
Project/
|-- src/
| |-- app/
| | |-- home/
| | | |-- home.component.spec.ts
| | |-- app-main.component.spec.ts
| |-- test.ts
| |-- tsconfig.spec.json
|-- angular.json
|-- package.json
|-- tsconfig.json
tsconfig.spec.json tsconfig.spec.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts",
"polyfills.ts",
"app/app-main.component.spec.ts"
// explicitly targetting spec.ts file works,
// but I want to add them to the include property
// "app/home/home.component.spec.ts" // this fixes it ...
],
"include": [
"**/*.spec.ts", // can't find app/app-main.component.spec.ts
"app/*.spec.ts", // can't find app/app-main.component.spec.ts
"**/**/*.spec.ts", // can't find app/home/home.component.spec.ts
"app/home/*.spec.ts", // can't find app/home/home.component.spec.ts
"**/*.d.ts"
]
}
It works only when I Add the spec files explicitly, I want to add those files/directory's to the include block so I don't need to explicitly add the spec files one by one.它仅在我显式添加规范文件时才有效,我想将这些文件/目录添加到包含块中,因此我不需要逐个显式添加规范文件。
But whatever I try to add in the include section it is not working.但是无论我尝试在包含部分中添加什么,它都不起作用。
You have to re-register the path from your tsconfig.json in your tsconfig.spec.json file.您必须在 tsconfig.spec.json 文件中从 tsconfig.json 重新注册路径。
For example, if you have the following in your tsconfig.json file例如,如果您的 tsconfig.json 文件中有以下内容
{
...
"paths": {
"@/*": [
"./*",
"app/*",
"src/app/*",
"../node_modules/*"
]
}
...
}
This also needs to be in your tsconfig.spec.json file.这也需要在您的 tsconfig.spec.json 文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.