7

In previous version, spec.ts can be disabled with .angular-cli.json as below. Is there any way to do it with angular.json in version 6.0.0?

"defaults": {
    "component": { 
        "spec": false 
    },
    "service": { 
        "spec": false 
    },
    ...
}
BSMP
  • 4,596
  • 8
  • 33
  • 44
Chanuka Asanka
  • 2,798
  • 3
  • 24
  • 36
  • 2
    Per https://github.com/angular/angular-cli/wiki/angular-workspace I'd guess you do it through the workspace schematics configuration. See e.g. https://github.com/angular/angular-cli/blob/v6.0.0-rc.8/packages/%40angular/cli/lib/config/schema.json#L74-L144 for components. – jonrsharpe May 05 '18 at 20:48
  • 1
    Thanks for the guide "@schematics/angular:component": { "prefix": "fmyp", "styleext": "css", "spec": false }, "@schematics/angular:directive": { "prefix": "fmp", "spec": false }, "@schematics/angular:module": { "spec": false } – Chanuka Asanka May 06 '18 at 03:25

5 Answers5

14

in version "6.0.0" *.spec.ts can be disabled with angular.json

NOTE: don't forget to change the "prefix" property values "fmyp" and "fmp" to yours.

"schematics": {
    "@schematics/angular:component": {
      "prefix": "fmyp",
      "styleext": "css",
      "spec": false
    },
    "@schematics/angular:directive": {
      "prefix": "fmp",
      "spec": false
    },
    "@schematics/angular:module": {
      "spec": false
    },
    "@schematics/angular:service": {
      "spec": false
    },
    "@schematics/angular:pipe": {
      "spec": false
    },
    "@schematics/angular:class": {
      "spec": false
    }
  }
Fouad Boukredine
  • 1,495
  • 14
  • 18
Chanuka Asanka
  • 2,798
  • 3
  • 24
  • 36
  • 1
    Note that since Angular 9 this option was renamed to `"skipTests": true`. When doing an ng update it should automatically correct this – Dan Manastireanu Aug 04 '20 at 14:28
11

Easy way is you can use CLI as you used with previous versions.

New syntax is ng generate component component-name --skipTests=true

This will create the component without .spec file. Happy coding :)

Anand Raja
  • 2,676
  • 1
  • 30
  • 35
10

Method 1:

You can also disable spec generation at the time of creating things using Angular-cli by adding "--no-spec"

ng generate component my-component --no-spec

Method 2: Permanently disable in angular.json file. You can edit the schematics for your 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
    }
  },
  • 1
    is the `--no-spec` option documented anywhere? Couldn't find it in the [ng g c](https://angular.io/cli/generate#component) documentation, or `ng g c --help` in the command line. – Joel Balmer Jul 01 '19 at 16:31
  • 4
    use `--skipTests=true` to generate without specs file – Anand Raja Feb 01 '20 at 18:47
1

The easiest way to do this without altering the angular.json file is to use this command(tried this in v13 and v14):

ng generate component test-component --skip-tests true

If you want to generate the ts and html file only in a subfolder then you need to use this command:

ng generate component test-component --skip-tests true --style none

And if you need them without any subfolder then use the following command:

ng generate component test-component --skip-tests true --style none --flat
Rahul
  • 493
  • 6
  • 27
0

// for ealier versions
ng generate component path/filename --no-spec
// Or
ng generate component path/filename --spec false

// for later versions
ng generate component path/filename --skipTests=true
// Note: path is relative to src/app folder