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
Just adding this bit of information because I found myself struggling with the same issue and could not fix it by using the current answer(s), plus I did not want to make the changes on the angular-cli.json
file. It appears the recent version of Angular CLI --spec=false
is depreciated and therefore no longer works, use --skipTests
instead.
Test on:
Angular CLI: 9.1.1
Node: 12.16.1
OS: win32 x64
Your command with then be:
ng g c mycomponent --skipTests
instead of
ng g c mycomponent --spec=false
PS: Always test your commands using the --dry-run
option to test your output.
For angular 8+ you just need to add
--skipTests=true
in the end
ng g c component-name --skipTests=true
g is abbreviated to generate. c is abbreviated to component
you can also use
ng generate component component-name --skipTests=true
When using angular-cli there is a bunch of options to pass. To generate a new component without tests, you can simply add --spec=false
like so:
ng generate component --spec=false my-component
There is also an option in the angular-cli.json for which types you want to enable specs by default, where you can modify the behaviour:
"defaults": {
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
Angular < 8
$ ng g component component-name --spec=false
Angular > 8
$ ng g component component-name --skipTests=false --flat
$ ng g component employee/listEmployees --skipTests=false --flat
ng g c component-name --spec false
There is a command for disabling Angular generate "spec" files by default
ng set defaults.class.spec=false
ng set defaults.component.spec=false
UPDATE: For Angular 6
ng config schematics.@schematics/angular.component.spec false