问题
In previous version, spec.ts can be disabled with .angular-cli.json as below. Is there any way to do it with angular.json in version 6.0.0?
"defaults": {
"component": {
"spec": false
},
"service": {
"spec": false
},
...
}
回答1:
in version "6.0.0" *.spec.ts can be disabled with angular.json
NOTE: don't forget to change the "prefix" property values "fmyp" and "fmp" to yours.
"schematics": {
"@schematics/angular:component": {
"prefix": "fmyp",
"styleext": "css",
"spec": false
},
"@schematics/angular:directive": {
"prefix": "fmp",
"spec": false
},
"@schematics/angular:module": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:class": {
"spec": false
}
}
回答2:
Method 1:
You can also disable spec generation at the time of creating things using Angular-cli by adding "--no-spec"
ng generate component my-component --no-spec
Method 2: Permanently disable in angular.json file. You can edit the schematics for your project.
"schematics": {
"@schematics/angular:component": {
"styleext": "scss",
"spec": false
},
"@schematics/angular:class": {
"spec": false
},
"@schematics/angular:directive": {
"spec": false
},
"@schematics/angular:guard": {
"spec": false
},
"@schematics/angular:module": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
}
},
回答3:
Easy way is you can use CLI as you used with previous versions.
New syntax is ng generate component component-name --skipTests=true
This will create the component with .spec file. Happy coding :)
来源:https://stackoverflow.com/questions/50193766/generating-components-without-spec-ts-in-angular-6