YUNOVA · Angular
Module 9: Testing Angular apps
Unit testing with Jasmine and Karma
Key points
- Jasmine gives describe, it and expect to write test specs.
- Karma runs the specs in a real browser and reports results.
- ng test starts Karma and reruns tests when files change.
Component testing with TestBed
Key points
- TestBed builds a testing module that declares the component.
- createComponent returns a fixture for the component and its DOM.
- Call fixture.detectChanges() to update the view after changing data.
Testing services and HTTP calls
Key points
- Services can be tested directly or injected through TestBed.
- HttpTestingController lets a test answer HTTP requests with fake data.
- Call verify() so no unexpected requests are left open.
End-to-end testing with Cypress
Key points
- Cypress drives the running app in a browser like a real user.
- cy.get, click and type find elements and act on them.
- End-to-end tests check whole flows, such as login, from start to finish.