Angular 6 + CLI (TypeScript) - How to stop generating .spec.ts test files

后端 未结 11 878
一向
一向 2020-12-13 05:52

I know it\'s kind of a bad practice, but bear with me:

I\'m using Angular-CLI, particularly ng g to generate all of my classes. However

相关标签:
11条回答
  • 2020-12-13 06:25

    You can run this command to disable spec file generation for a specific type of file:

    ng set defaults.spec.FILETYPE false

    For example:

    ng set defaults.spec.component false // Won't generate spec files for .component files

    Alternately you can just disable all spec file generation from the angular-cli.json file.

    {
      ...
      "defaults": {
        "spec": {
          "class": false,
          "component": false,
          "directive": false,
          "module": false,
          "pipe": false,
          "service": false
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-13 06:25

    you can add --spec=false

    example

    ng g c home --spec=false
    

    log will be

    CREATE src/app/home/home.component.scss (0 bytes)
    CREATE src/app/home/home.component.html (23 bytes)
    CREATE src/app/home/home.component.ts (262 bytes)
    UPDATE src/app/app.module.ts (467 bytes)
    
    0 讨论(0)
  • 2020-12-13 06:25

    you can add --skipTests=true|false if true it wont generate any spec.ts

    example : ng g component componentName --skipTests=true

    this line wont generate any spec.ts files

    EDIT:

    Note: As of angular 7 this command doesn't work, even though this command is mentioned on the official website of angular. Here: https://angular.io/cli/generate#component

    0 讨论(0)
  • 2020-12-13 06:30

    you can try --skip-tests when you creating your app like below.

    ng new yourProjectName --skip-tests

    0 讨论(0)
  • 2020-12-13 06:31

    Add Following code on Angular.json

    "schematics": {
        "@schematics/angular": {
          "component": {
            "spec": false
          }
        }
      }
    
    0 讨论(0)
提交回复
热议问题