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”
Option
--skipTests=true|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.
app.module.ts
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' @NgModule({ declarations: [ AppComponent, RecipesComponent ], imports: [ BrowserModule, AppRoutingModule ], 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.
--spec=true|false
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:
- Get index of ngFor element using index as value in attribute
- Set default value in the dropdown list in Angular 9
- Dynamic and conditional CSS classes with ngClass : Angular
- Apply CSS style attribute dynamically with ngStyle : Angular 9
- How to declare model class and use in Angular component : Typescript ?
- HTML Property Binding in Angular : Data Binding
- This version of CLI is only compatible with Angular versions
- Global Angular CLI version is greater than your local version
- Create custom events and fire in Angular 9 with EventEmitter – Example
- Display different colors for odd/even rows using ngFor loop and ngClass
- ERROR in multi /bootstrap.min.css ./src/styles.css in Angular 9
- Bind selected element from drop down to an object in Angular 9
- TrackBy with *ngFor in Angular 9 : Example
- Angular 9 EventEmitter – Custom Events : Example
- Angular 9 Error : ‘app-header’ is not a known element
thank you!