Image for post
Image for post

Disclaimer: This article assumes you have a basic knowledge of the Angular web development framework. Otherwise, it probably won’t make all that much sense to you.

If you’ve ever created a new component in Angular, using the Angular CLI (ng generate component x), then no doubt you’re familiar with the fact that it generates a bunch of files for you. Four, to be exact. Those are:

  1. x.component.html (html template — skeleton).
  2. x.component.css (styling of html template — makes it pretty).
  3. x.component.ts (defines logic associated with view — makes it work).
  4. x.component.spec (defines unit-test — huh?).

What’s with that last file? Why do you need that?

By default, Angular creates a spec file, containing a unit-test for your newly-created component. These tests are run using the Jasmine test framework whenever you execute the ng test command. For a lot of developers, myself included, these spec files remain untouched and your application can function properly without them. As a result, these files are usually deleted. Rather than having to manually delete these files whenever you create a new component, there is a way to prevent them from being generated in the first place.

Within your application’s src folder, there is a .angular-cli.json file. This file contains CLI configurations for your Angular application. Within this file, there is a “defaults” object, containing a “styleExt” and “component” property. Add a new object to “defaults”, called “spec”. Within “spec”, add a “component” property whose value is false. Example:

With this configuration, generated components will no longer come with a spec file. Now, you won’t have to worry about manually deleting them. This is not to say the spec files are without value, however if your goal is to develop fast without worrying about unit-tests, then you can probably go without them in the beginning.

Interested in Computer Science, education and world domination.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store