Angular 11 CLI,"ng generate" 选项:--skip-tests
Angular 11 CLI, "ng generate" option: --skip-tests
使用 Angular 11 CLI 时,当我 generate 一个新组件时,我可以指定选项 --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
?
--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
&&
表示仅当command1执行成功后才执行command2。
请注意 vscode 集成终端 不支持 &&,可以找到可能的解决方法 here
结果应该是这样的:
我正在使用 angular CLI 版本 10,但是 angular cli v11 应该会产生相同的结果。
根据 this article,您可以在生成整个项目时添加 --skip-tests
标志,或者生成单个组件。从逻辑的角度来看,你不能在模块上应用标志是有道理的,因为模块不是用测试文件生成的。
要对所有未来生成的代码进行更改,请通过将 skipTests:true
添加到原理图部分来修改您的 angular.json
文件。
"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
}
}
使用 Angular 11 CLI 时,当我 generate 一个新组件时,我可以指定选项 --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
?
--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
&&
表示仅当command1执行成功后才执行command2。
请注意 vscode 集成终端 不支持 &&,可以找到可能的解决方法 here
结果应该是这样的:
我正在使用 angular CLI 版本 10,但是 angular cli v11 应该会产生相同的结果。
根据 this article,您可以在生成整个项目时添加 --skip-tests
标志,或者生成单个组件。从逻辑的角度来看,你不能在模块上应用标志是有道理的,因为模块不是用测试文件生成的。
要对所有未来生成的代码进行更改,请通过将 skipTests:true
添加到原理图部分来修改您的 angular.json
文件。
"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
}
}