Generating Component without spec.ts file in Angular 2+

前端 未结 25 968
轮回少年
轮回少年 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:58

    Just adding this bit of information because I found myself struggling with the same issue and could not fix it by using the current answer(s), plus I did not want to make the changes on the angular-cli.json file. It appears the recent version of Angular CLI --spec=false is depreciated and therefore no longer works, use --skipTests instead.

    Test on:

    Angular CLI: 9.1.1
    Node: 12.16.1
    OS: win32 x64
    

    Your command with then be: ng g c mycomponent --skipTests instead of ng g c mycomponent --spec=false

    PS: Always test your commands using the --dry-run option to test your output.

    0 讨论(0)
  • 2021-02-01 00:59

    For angular 8+ you just need to add

    --skipTests=true

    in the end

    ng g c component-name --skipTests=true
    

    g is abbreviated to generate. c is abbreviated to component

    you can also use

    ng generate component component-name --skipTests=true
    
    0 讨论(0)
  • 2021-02-01 01:07

    When using angular-cli there is a bunch of options to pass. To generate a new component without tests, you can simply add --spec=false like so:

    ng generate component --spec=false my-component
    

    There is also an option in the angular-cli.json for which types you want to enable specs by default, where you can modify the behaviour:

    "defaults": {
      "spec": {
        "class": false,
        "component": true,
        "directive": true,
        "module": false,
        "pipe": true,
        "service": true
      }
    }
    
    0 讨论(0)
  • 2021-02-01 01:08

    Angular < 8 $ ng g component component-name --spec=false

    Angular > 8 $ ng g component component-name --skipTests=false --flat

       $ ng g component employee/listEmployees --skipTests=false --flat
    
    0 讨论(0)
  • 2021-02-01 01:10
    ng g c component-name --spec false
    
    0 讨论(0)
  • 2021-02-01 01:11

    There is a command for disabling Angular generate "spec" files by default

    ng set defaults.class.spec=false
    ng set defaults.component.spec=false
    

    UPDATE: For Angular 6

    ng config schematics.@schematics/angular.component.spec false

    0 讨论(0)
提交回复
热议问题