6

In Angular 5 and earlier versions, to stop generating the spec files while generationg a component we had to add the following in .angular-cli.json file:

{
  ...
  "defaults": {
    "spec": {
      "class": false,
      "component": false,
      "directive": false,
      "module": false,
      "pipe": false,
      "service": false
    }
  }
}

in Angular 6+, following this link we have to add the next in the new angular.json file, under the schematics section:

  ....
  "schematics": {
    "@schematics/angular:component": {
      ....
      "properties": {
        ....
        "spec": {
          "type": "boolean",
          "description": "Specifies if a spec file is generated.",
          "default": false
        }
      }          
    }
  },

But when generating a new component a new spec file is still created, even after IDE restart, what is missing ?

Sami-L
  • 5,553
  • 18
  • 59
  • 87
  • Possible duplicate of [Angular 6 + CLI (TypeScript) - How to stop generating .spec.ts test files](https://stackoverflow.com/questions/42049756/angular-6-cli-typescript-how-to-stop-generating-spec-ts-test-files) – Brampage May 16 '19 at 10:06

3 Answers3

9

You can set it in the angular-cli.json as

{
  "defaults": {
    "component": {
      "spec": false
    }
  }
}

This will disable generating all spec files. If you want to disable on a specific component,

ng g c component-name --spec false
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • You repeat what is in the question, please consider that I am asking how to set it in angular.json file not in .angular-cli.json, this question is related to Angular 6. – Sami-L May 27 '18 at 02:09
  • is not the same with angular.json as well? "@schematics/angular:component": { "prefix": "fmyp", "styleext": "css", "spec": false }, – Sajeetharan May 27 '18 at 02:15
  • No sorry, not the same way, .angular-cli.json is deprecated for versions above 5.x. – Sami-L May 27 '18 at 02:26
6

Thanks to the link provided here by G. Ross, the solution despite it doesn't match the official documentation of Angular 6 but it worked for me.

added the next in the "angular.json" file, under the schematics section:

  ....
  "schematics": {
    "@schematics/angular:component": {
      ....
      "spec": false,
      ....
    }
  },
Sami-L
  • 5,553
  • 18
  • 59
  • 87
0

You can simply use to generate a component without its spec files ng g c NewComponent --spec=false

bluecouch
  • 193
  • 3
  • 12
  • This is not an automated way. – Sami-L May 26 '18 at 23:47
  • 1
    Try [this](https://stackoverflow.com/questions/50193766/generating-components-without-spec-ts-in-angular-6?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – bluecouch May 26 '18 at 23:50
  • It worked despite this doesn't match the official documentation of Angular 6: https://github.com/angular/angular-cli/blob/29c1d9d3afc5da93d0118876db39a93e5384b906/packages/%40angular/cli/lib/config/schema.json#L74-L144 – Sami-L May 26 '18 at 23:57
  • Please post a complete answer with explanation to help others, thank you. – Sami-L May 27 '18 at 00:01