angular tutorials

How to stop generation of .spec.ts test files using Angular CLI ?

This tutorial guides you on how to stop generation of .spec.ts test files when you create angular component using Angular CLI command.

Stop generation of .spec.ts test files using Angular CLI

Are you using Angular-CLI ? In particular ng g c command to generate components in your angular application and not interested to generate .spec.ts test files automatically ?

The following command will generate all classes for your new component including .spect.ts test files.

Generate new component and its classes

ng generate component <component-name> [options]

ng g c <component-name> [options]

When the following option is used with ng g c command with value as “true”, then it will stop generation of .spec.ts test files for the new component. The default value for this option is “false”



Therefore, basically you need to run the following ng g c command as shown below. You can notice that it did not generate .spec.ts test file in the component folder.

> ng g c recipes --skipTests true

CREATE src/app/recipes/recipes.component.html (22 bytes)
CREATE src/app/recipes/recipes.component.ts (279 bytes)
CREATE src/app/recipes/recipes.component.css (0 bytes)
UPDATE src/app/app.module.ts (560 bytes)

Note, the above command also takes care of updating App Module (app.module.ts) to register your new component, so that you can use in your angular application.


import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { RecipesComponent } from './recipes/recipes.component'

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }

Unknown option: ‘–spec’

Note, the old versions of angular CLI uses the following option to stop generation of .spec.ts test files.


The above command is changed now. Therefore you should use “–skiptTests true” instead of “–spec false” if you are seeing the below error.

> ng g c recipes --spec false

Unknown option: '--spec'
Unknown option: 'false'

Hope it helped 🙂

Also See:


Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
ginger thailand
ginger thailand
2 years ago

thank you!