Trigger Change Detection

We use fixture.detectChanges in the tests to instruct Angular to run change detection before doing our assertions with Jasmine’s expect.

it("should display the course list", () => {
    component.courses = setupCourses();
    fixture.detectChanges();
    //console.log(el.nativeElement.outerHTML);
    
    const cards = el.queryAll(By.css(".course-card"));
    expect(cards).toBeTruthy("Could not find cards");
    expect(cards.length).toBe(12, "Unexpected number or courses");
});

We use the detectChanges in order to apply data to the component template

Last updated