在 Angular 2+ 中生成没有 spec.ts 文件的组件 [英] Generating Component without spec.ts file in Angular 2+

查看:39
本文介绍了在 Angular 2+ 中生成没有 spec.ts 文件的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我创建一个新组件时,有没有办法摆脱 Angular 2+ 中的 spec.ts 文件.我知道这是为了测试目的,但如果我不需要它怎么办.

Is there a way to get rid of the spec.ts file in Angular 2+, whenever I create a new component. I know this is for testing purpose but what if I don't need it.

可能有一些设置可以禁用这个特定的测试文件.

May be there is some setting to disable this specific testing file.

推荐答案

针对 Angular >=8 CLI 进行了更新

对于一个组件,使用以下命令:

For one component use the following command:

ng generate component --skip-tests=true component-name

对于单个项目,在您的 angular.json 中更改或添加以下内容:

For a single project, change or add the following in your angular.json:

{ 
  "projects": {
    "{PROJECT_NAME}": {
      "schematics": {
        "@schematics/angular:component": {
          "skipTests": true
        }
      }
    }
  }
}

对于所有项目的全局设置,请在 angular.json 中更改或添加以下内容:

For a global setting for all your projects, change or add the following in your angular.json:

{ 
  "schematics": {
    "@schematics/angular:component": {
      "skipTests": true
    }
  }
}

或者使用命令行

ng config schematics.@schematics/angular:component.skipTests true


<角 8

在您的 angular-cli.json 中,将 spec.component 参数设置为 false:

Inside your angular-cli.json set the spec.component parameter to false:

{
   ...
   "defaults" : {
       ...
       "spec": {
           ...
           "component": false
       }
   }
}

或在创建过程中使用 --spec=false 选项

or use the --spec=false option during creation

ng generate component --spec=false component-name

这篇关于在 Angular 2+ 中生成没有 spec.ts 文件的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆