saa*_*eez 33 angular-cli angular-components angular
每当我创建一个新组件时,有没有办法摆脱Angularjs 2中的spec.ts文件.我知道这是出于测试目的,但如果我不需要它会怎样.
可能有一些设置来禁用此特定测试文件.
Pie*_*Duc 66
在您的angular-cli.json设置中,spec.component参数为false:
ng generate component --skipTests=true component-name
Run Code Online (Sandbox Code Playgroud)
或--spec=false在创建过程中使用该选项
{
...
"defaults" : {
...
"spec": {
...
"component": false
}
}
}
Run Code Online (Sandbox Code Playgroud)
Fra*_*ous 16
对于Angular 6
ng config schematics.@schematics/angular.component.spec false
Run Code Online (Sandbox Code Playgroud)
使用angular-cli时,有许多选项可以通过.要生成没有测试的新组件,您可以简单地添加--spec=false如下:
ng generate component --spec=false my-component
Run Code Online (Sandbox Code Playgroud)
angular-cli.json中还有一个选项,默认情况下您要为哪些类型启用规范,您可以在其中修改行为:
"defaults": {
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
Run Code Online (Sandbox Code Playgroud)
对于 Angular 7 及更高版本,这将起作用:
ng generate component componentname --skipTests
Run Code Online (Sandbox Code Playgroud)
或者
ng generate component componentname --skipTests=true
对于角度为6+的用户,只需运行以下命令:
ng config schematics.@schematics/angular.component.spec false
Run Code Online (Sandbox Code Playgroud)
要么
只需将其添加到您的angular.json文件中,您就可以开始了
"schematics": {
"@schematics/angular": {
"component": {
"spec": false
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:在粘贴此检查是否有冲突之前,希望它会有所帮助
ng generate component your-component-name --skipTests=true
Run Code Online (Sandbox Code Playgroud)
或使用别名s代替--skipTests
ng generate component your-component-name -s=true
Run Code Online (Sandbox Code Playgroud)
angular.json以避免始终使用上述 CLI 命令将以下代码段复制到projects.your-project-name其angular.json.
下面将确保.spec不会使用命令为Components、Class、Directives、Pipe和Service创建文件ng generate。您可以根据需要选择这些。
{
...
"projects": {
"your-project-name": {
...
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
...
}
Run Code Online (Sandbox Code Playgroud)
PS:该--spec=false选项现已弃用,无法使用
在最新的Angular版本中,您可以按以下方式配置cli生成器以禁止为组件和服务创建规范文件angular-cli.json:
"defaults": {
"component": { "spec": false },
"service": { "spec": false },
...
}
Run Code Online (Sandbox Code Playgroud)
您可以添加额外的行以禁用防护和类等的规范。
| 归档时间: |
|
| 查看次数: |
38057 次 |
| 最近记录: |