When using the Angular 11 CLI, when I generate a new component I can specify the option --skip-tests to avoid generating a .component.spec.ts at this stage.
ng generate component --name asdf --module app --skip-tests --dry-run
When I generate a new module containing a new component (--route option) I can't specify the --skip-tests option.
ng generate module --name asdf --module app --route asdf --routing true --skip-tests --dry-run
If I do I get the error:
Unknown option: '--skip-tests'
Is there another way to skip generating the test in this case or is it just not supported for generate module?
According to this article, you can either add the --skip-tests flag upon generating the project as a whole, or generating individual components. From a logical perspective, it makes sense that you could not apply the flag on a module, since modules are not generated with test files.
To make the change for all future generated code, modify your angular.json file by adding the skipTests:true to the schematics section.
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:module": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
}
--skip-tests is not supported by the ng generate module command.
supported options are :
--flat--lint-fix--module--project--route--routing--routing-scopeUPDATE:
an alternative is to use two commands sequencially:
ng generate module --name am && ng generate component --name ac --module am --skip-tests --dry-run
&& means Execute command2 only if the execution of command1 has finished successfully.
note that && is not supported in vscode integrated terminal, possible workaround can be find here
The result should be something like this:

Am using angular CLI version 10, but angular cli v11 should yield the same results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With