Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angular-cli

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?

like image 421
user2846469 Avatar asked Jan 20 '26 19:01

user2846469


2 Answers

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
        }
     }
like image 100
PMO1948 Avatar answered Jan 22 '26 09:01

PMO1948


--skip-tests is not supported by the ng generate module command.

supported options are :

  • --flat
  • --lint-fix
  • --module
  • --project
  • --route
  • --routing
  • --routing-scope

UPDATE:

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:

enter image description here

Am using angular CLI version 10, but angular cli v11 should yield the same results.

like image 36
Benzara Tahar Avatar answered Jan 22 '26 07:01

Benzara Tahar