Is there a way to get rid of the spec.ts file in Angular 2+, whenever I create a new component. I know this is for testing purpose but what if I don\'t need it.
May be t
It is very easy to do. While creating the component add
--skipTests=true
ng generate component --skipTests=true componentName
Or
ng g c --skipTests=true componentName
ng generate component your-component-name --skipTests=true
or using the alias s
instead of --skipTests
ng generate component your-component-name -s=true
angular.json
to avoid using above CLI command alwaysCopy the below snippet to the root of a specific project (projects.your-project-name
) in its angular.json
.
The below will ensure .spec
files are not created for Components, Class, Directives, Pipe and Service with the ng generate
command. You may choose the ones as per requirement.
{
...
"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
}
},
...
}
PS: The --spec=false
option is now deprecated and will not work
Use also the following command if you want to skip your spec.ts file:
ng g c try-it --skipTests=true
where
g c
=> generate component ,
try-it
=> component name ,
--skipTest=true
=> == -- spec false
.
For Angular 6
ng config schematics.@schematics/angular.component.spec false
For angular 6+ Simply run this command:
ng config schematics.@schematics/angular.component.spec false
OR
just add this in your angular.json file and you're good to go
"schematics": {
"@schematics/angular": {
"component": {
"spec": false
}
}
}
NOTE: before pasting this check for conflicts, hope it helps
simply try this one. this is working
ng g c component_name --spec false