I know it's kind of a bad practice,但请容忍我:

我使用Angular CLI,尤其是ng g来生成我的所有类.然而,我对任何*.spec.ts个测试文件都不感兴趣.我知道有两个标志(--inline-template--inline-style)来处理内联CSS和HTML,而不是单独的文件,对于spec,默认情况下--spec标志设置为true.

所以每跑一次,是的,我可以跑ng g c foo --it --is --spec=false次.

但是,如何在全局范围内禁用测试文件的创建?它有默认设置吗?

我轻率地做了一些事情,比如:

ng set spec=false --global

我还try 通过填充排除数组来配置我的src/tsconfig.json:

"exclude": [
    "**/*.spec.ts"
]

推荐答案

对于Angular 9>(以下版本6>)

1) Copy snippet to the root of angular.json, (configures settings to all projects/globally).
2) Or copy snippet to the root of a specific project (projects.your-project-name) in angular.json (configures settings for a specific project).

"schematics": {
  "@schematics/angular:component": {
    "style": "scss",
    "skipTests": true
  },
  "@schematics/angular:class": {
    "skipTests": true
  },
  "@schematics/angular:directive": {
    "skipTests": true
  },
  "@schematics/angular:pipe": {
    "skipTests": true
  },
  "@schematics/angular:service": {
    "skipTests": true
  }
},

All configurable options per type of file 100:

"schematics": {
  "@schematics/angular:component": {
    "changeDetection": "Default",
    "entryComponent": false,
    "export": false,
    "flat": false,
    "inlineStyle": false,
    "inlineTemplate": false,
    "module": "",
    "prefix": "",
    "selector": "",
    "skipImport": false,
    "spec": true,
    "style": "css",
    "viewEncapsulation": "Emulated",
    "skipTests": "false"
  },
  "@schematics/angular:module": {
    "commonModule": true,
    "flat": false,
    "module": "",
    "routing": false,
    "routingScope": "Child"
  },
  "@schematics/angular:service": {
    "flat": true,
    "skipTests": true
  },
  "@schematics/angular:pipe": {
    "export": false,
    "flat": true,
    "module": "",
    "skipImport": false,
    "skipTests": true
  },
  "@schematics/angular:directive": {
    "export": false,
    "flat": true,
    "module": "",
    "prefix": "app",
    "selector": "",
    "skipImport": false,
    "skipTests": true
  },
  "@schematics/angular:class": {
    "skipTests": true
  }
},

对于Angular 6>

1) Copy snippet to the root of angular.json, (configures settings to all projects/globally).
2) Or copy snippet to the root of a specific project (projects.your-project-name) in angular.json (configures settings for a specific project).

"schematics": {
  "@schematics/angular:component": {
    "styleext": "scss",
    "spec": false
  },
  "@schematics/angular:class": {
    "spec": false
  },
  "@schematics/angular:directive": {
    "spec": false
  },
  "@schematics/angular:guard": {
    "spec": false
  },
  "@schematics/angular:module": {
    "spec": false
  },
  "@schematics/angular:pipe": {
    "spec": false
  },
  "@schematics/angular:service": {
    "spec": false
  }
},

All configurable options per type of file (100):

"schematics": {
  "@schematics/angular:component": {
    "changeDetection": "Default",
    "export": false,
    "flat": false,
    "inlineStyle": false,
    "inlineTemplate": false,
    "module": "",
    "prefix": "",
    "selector": "",
    "skipImport": false,
    "spec": true,
    "styleext": "css",
    "viewEncapsulation": "Emulated"
  },
  "@schematics/angular:module": {
    "commonModule": true,
    "flat": false,
    "module": "",
    "routing": false,
    "routingScope": "Child",
    "spec": true
  },
  "@schematics/angular:service": {
    "flat": true,
    "spec": true
  },
  "@schematics/angular:pipe": {
    "export": false,
    "flat": true,
    "module": "",
    "skipImport": false,
    "spec": true
  },
  "@schematics/angular:directive": {
    "export": false,
    "flat": true,
    "module": "",
    "prefix": "app",
    "selector": "",
    "skipImport": false,
    "spec": true
  },
  "@schematics/angular:class": {
    "spec": true
  }
},

带Angular CLI的Angular CLI配置

ERROR:

ng set defaults.spec.component false命令导致错误:get/set have been deprecated in favor of the config command.

ng set变成了ng config.

Using the Angular CLI (config command usage):

angular.json中生成规格、内联模板、内联样式等的设置现在保存在schematics.@schematics/angular.<file-type>.<setting>中.

运行ng config schematics.@schematics/angular.component.spec false为组件配置规格.此命令在angular.json文件的schematics属性中添加设置.


Angular CLI workspace file (angular.json) on Angular Github

Schematic options inside schema.json

How to do X in Angular CLI v6

Typescript相关问答推荐

具有映射返回类型的通用设置实用程序

如何在ts中使用函数重载推断参数类型

即使子网是公共的,AWS CDK EventBridge ECS任务也无法分配公共IP地址

带有联合参数的静态大小数组

是否可以根据嵌套属性来更改接口中属性的类型?

忽略和K的定义

对深度对象键/路径进行适当的智能感知和类型判断,作为函数参数,而不会触发递归类型限制器

根据另一个属性的值来推断属性的类型

使某些(嵌套)属性成为可选属性

是否有一个版本的联合类型递归地使属性只出现在一个可选选项中?

如何将泛型对象作为返回类型添加到类型脚本中

已解决:如何使用值类型限制泛型键?

下载量怎么会超过下载量?

带有';的类型脚本嵌套对象可选属性错误满足';

替换typescript错误;X类型的表达式可以';t用于索引类型Y;带有未定义

如何创建允许使用带有联合类型参数的Array.from()的TS函数?

const nav: typechecking = useNavigation() 和 const nav = useNavigation() 之间有什么区别?

为什么 typescript 在对象合并期间无法判断无效键?

是否有解释为什么默认情况下在泛型类型上访问的属性不是索引访问

类型string不可分配给类型string| 联盟| 的'