I want to test the error handling in my Angular2 component and therefore want to mock a service to return an Observable.throw(\'error\'). How can that be done using Jasmine and
You can simply mock Observable
and throw error object using Observable.throw({status: 404})
and test error block of observable.
const xService = fixture.debugElement.injector.get(SomeService);
const mockCall = spyOn(xService, 'xMethod')
.and.returnValue(Observable.throw({status: 404}));
Here I am throwing http 404
error from Observable.throw({status: 404})
by mocking xMethod
of xSerive
in my test.