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')
- http://chariotsolutions.com/blog/post/testing-angular-2-components-unit-tests-testcomponentbuilder/
- http://blog.rangle.io/testing-angular-2-applications/
- http://www.itsmycodeblog.com/angular2-unit-testing-a-component/
- https://developers.livechatinc.com/blog/testing-angular-2-apps-dependency-injection-and-components/
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?