In angular 1, if I wrote a component, I would make sure that:
- Dependencies, such as services is being mocked.
- Unit tests are written for methods within the component.
- The component is calling the service to retrieve the data
expect(service.method).toHaveBeenCalled() - The component is updating the view given an updated model.
I've been doing some research on Angular 2 component testing, and for all the articles I can find, it seems that testing is being done as follows;
- Create a service mock that returns a fixed result (ex: 'Test Quote')
- Expect that the view contains the result coming from the mocked service (ex; that there's a div somewhere that has
<div>Test Quote</div>).
Here are a few examples of such articles (basically top results on google for 'Angular 2 Component Testing')
Since NG2 provides no spies in it's testing framework @angular/core/testing, it's recommended to avoid the step in bold altogether? Or should we be including jasmine to just have access to spies?
Aucun commentaire:
Enregistrer un commentaire