当使用角11 CLI时,当我生成一个新的组件时,我可以指定选项--skip-tests以避免在这个阶段生成.component.spec.ts。
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不支持它?
发布于 2021-02-17 13:26:24
根据这篇文章,您可以在生成整个项目时添加--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
}
}发布于 2021-02-17 13:25:04
--skip-tests命令不支持ng generate module。
--flat--lint-fix--module--project--route--routing--routing-scope更新:
另一种方法是按顺序使用两个命令:
ng generate module --name am && ng generate component --name ac --module am --skip-tests --dry-run &&意味着只有在command2的执行成功完成时才能执行command1。
注意:在vscode集成终端中不支持&&,可能的解决方法可以找到这里
结果应该是这样的:

我使用的是角CLI版本10,但是角cli v11应该会产生同样的结果。
发布于 2022-11-29 11:13:30
使用以下命令跳过测试文件:ng g名称--跳过- test
https://stackoverflow.com/questions/66242718
复制相似问题