Skip to Main Content
Mastering TypeScript 3 - Third Edition
book

Mastering TypeScript 3 - Third Edition

by Nathan Rozentals
February 2019
Beginner content levelBeginner
694 pages
18h 4m
English
Packt Publishing
Content preview from Mastering TypeScript 3 - Third Edition

Angular rendering tests

We can now turn our attention to the generated HTML that our app produces, and test whether our component has rendered elements to the DOM correctly, as follows:

it("should render 0 - none selected to the DOM", () => { 
    fixture.detectChanges(); 
    fixture.whenStable().then(() => { 
        const domElement = fixture.debugElement.nativeElement; 
 
        let selectedItemDiv =  
            domElement.querySelector("#selectedItemText"); 
        expect(selectedItemDiv).toBeTruthy(); 
        expect(selectedItemDiv.innerHTML).toContain('0 - None selected'); 
    }); 
}); 

Here, we have defined a test that will check that the text, 0 - none selected, has been rendered to the DOM. Our test starts with a call to the fixture.detectChanges function. This function is provided by the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The TypeScript Workshop

The TypeScript Workshop

Ben Grynhaus, Jordan Hudgens, Rayon Hunte, Matt Morgan, Wekoslav Stefanovski

Publisher Resources

ISBN: 9781789536706Supplemental Content