Angular unit tests
Just because your Angular app launches using npm start
and seems to work fine, it doesn't mean it is error free or production ready. As covered earlier in Chapter 2, Create a Local Weather Web Application, Angular CLI creates a unit test file as you create new components and services, such as current-weather.component.spec.ts
and weather.service.spec.ts
.
At their most basic, these unit default unit tests ensure that your new components and services can be properly instantiated in the test harness. Take a look at the following spec file and observe the should create
test. The framework asserts that component of the CurrentWeatherComponent
type to not be null or undefined, but be truthy:
src/app/current-weather/current-weather.component.spec.ts
describe('CurrentWeatherComponent', () => {
let component: CurrentWeatherComponent
let fixture: ComponentFixture<CurrentWeatherComponent>
beforeEach(
async(() => {
TestBed.configureTestingModule({
...