Generating Component without spec.ts file in Angular 2+

前端 未结 25 988
轮回少年
轮回少年 2021-02-01 00:48

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 t

25条回答
  •  深忆病人
    2021-02-01 00:57

    Latest Angular 9 Compatible

    CLI Command

    ng generate component your-component-name --skipTests=true
    

    or using the alias s instead of --skipTests

    ng generate component your-component-name -s=true
    

    Modifying angular.json to avoid using above CLI command always

    Copy the below snippet to the root of a specific project (projects.your-project-name) in its angular.json.

    The below will ensure .spec files are not created for Components, Class, Directives, Pipe and Service with the ng generate command. You may choose the ones as per requirement.

    {
      ...
      "projects": {
        "your-project-name": {
          ...
          "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
            }
          },
        ...
    }
    

    PS: The --spec=false option is now deprecated and will not work

提交回复
热议问题