Angular11CLI,“nggenerate”选项:–skip-tests

使用 Angular 11 CLI 时,当我生成新组件时,我可以指定选项--skip-tests以避免.component.spec.ts在此阶段生成 a 。

ng generate component --name asdf --module app --skip-tests --dry-run

当我生成一个包含新组件(--route选项)的新模块时,我无法指定该--skip-tests选项。

ng generate module --name asdf --module app --route asdf --routing true --skip-tests --dry-run

如果我这样做,我会收到错误:

Unknown option: '--skip-tests'

在这种情况下,是否有另一种方法可以跳过生成测试,或者只是不支持generate module

回答

根据这篇文章,您可以--skip-tests在生成整个项目时添加标志,也可以生成单个组件。从逻辑的角度来看,您不能在模块上应用标志是有道理的,因为模块不是用测试文件生成的。

要对所有未来生成的代码进行更改,请angular.json通过将 加入skipTests:true到原理图部分来修改您的文件。

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


以上是Angular11CLI,“nggenerate”选项:–skip-tests的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>