Is there a way to get rid of the spec.ts file in Angular 2+, whenever I create a new component. I know this is for testing purpose but what if I don't need it.
May be there is some setting to disable this specific testing file.
You have to use "--skip-tests true" when generating component. (Note: you can get the above version info by trying "ng v" or "ng -v" in the terminal). You can get the complete list of switches for "ng g c (short for ng generate component)" using "ng g c --help". Alternatively you can add a component manually.
if you generate new angular project using "ng new", you may skip a generating of spec. ts files. For this you should apply --skip-tests option.
Select an Angular *. ts file and use right click to generate the spec file. Generate spec (jest / jasmine / mockito / empty) files for Angular elements: component.
Updated for Angular >=8 CLI
For one component use the following command:
ng generate component --skip-tests=true component-name
For a single project, change or add the following in your angular.json
:
{ "projects": { "{PROJECT_NAME}": { "schematics": { "@schematics/angular:component": { "skipTests": true } } } } }
For a global setting for all your projects, change or add the following in your angular.json
:
{ "schematics": { "@schematics/angular:component": { "skipTests": true } } }
Or by using the command line
ng config schematics.@schematics/angular:component.skipTests true
< Angular 8
Inside your angular-cli.json
set the spec.component parameter to false
:
{ ... "defaults" : { ... "spec": { ... "component": false } } }
or use the --spec=false
option during creation
ng generate component --spec=false component-name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With