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

查看:413
本文介绍了在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 --skipTests=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天全站免登陆