Skip to main content

TestBed, components, services and DI

Learn TestBed, components, services and DI (Module 20 · Angular Testing, Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Angular testing utilities Angular testing utilities live in @angular/core/testing . TestBed creates a mini Angular environment for a test, like a small stage where you place only the actors (components, providers) you need. ComponentFixture is the handle to the created component: fixture.componentInstance (the class), fixture.nativeElement (the DOM) and fixture.detectChanges() (run change detection so the template updates). Component testing : create it, change state, detect changes, assert on DOM text.

More lessons in Module 20 · Angular Testing