December 2017
Beginner
372 pages
10h 32m
English
The last test case we have is to test the add board functionality. Here, we will check if a new board is added to the UI successfully. The following is the code for the test case:
it('create a new board',()=>{ component.addBoard(); fixture.detectChanges(); expect(component.boards.length).toBe(1); const compiled = fixture.debugElement.nativeElement; let title = compiled.querySelectorAll('.title') ; expect(title.length).toBe(2); expect(title[0].textContent).toContain('New Board'); });
Here, we first call the addBoard method on our component, and then to make sure that Angular refreshes its bindings, we call the detectChanges method.
Once done, we assert the expect statements to check if the number of boards is equal ...
Read now
Unlock full access