Unit testing

Although we won't cover testing until the last chapter of this book, it pays to make testing a habit. This is why we are going to explore the simplicity of testing components here.

Basically, Angular provides an abstraction layer for testing your components with the help of TestBed. You don't need to run your entire application before you can see whether your components behave as planned. A simple test comes bundled with the CLI scaffold for our app component. It can be found adjacent to the file (which is a common and good practice) as app.component.spec.ts.

Let's view the contents of this file:

import { TestBed, async } from '@angular/core/testing';  import { AppComponent } from './app.component';  describe('AppComponent', ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.