Search code examples
angular-cli

Angular 11 CLI, "ng generate" option: --skip-tests


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?


Solution

  • 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
            }
         }