Mohamed Kawsara Mohamed Kawsara - 4 years ago 226
TypeScript Question

Angular2 CLI (TypeScript) - How to stop generating .spec.ts test files

I KNOW IT'S KIND OF A BAD PRACTICE, but pair with me:

I'm using Angular-CLI and particularly

ng g
to generate all of my classes, however, I'm not interested in any test file
and I know that there are two flags (
) to handle inline CSS and HTML instead of separated files.
and for spec the default flag is set to true

So for each run, yes, I can do so
ng g c foo --it --is --spec=false

But How to disable the creation of test files globally? is there any default setting for it?

Rashly, I did some stuff like (that didn't work):

ng set spec=false --global

Then tried configuring ts settings file
by filling the exclude array.

"exclude": [

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download