I am trying to write a test case for the following function:
foo = () => {
this.someService.getDetails({key:'value'}).subscribe(details => {
//do stuff
this.someService.getMoreDetails().subscribe(moreDetails => {
//do stuff
});
});
}
The service looks like this:
getDetails = (args) :Observable<any> {
return this.http.post<any>(//calls)
}
// similar for getMoreDetails
The test file that I have written looks like this:
const someServiceStub = jasmine.createSpyObj('someService', ['getDetails', 'getMoreDetails']);
...
...
it('should called getMoreDetails', () => {
component.foo();
fixture.detectChanges();
someServiceStub.getDetails.and.returnValue(Observable.of
({ Details: 'Tired of giving you details'})
);
expect(someServiceStub.getMoreDetails).toHaveBeenCalled();
});
However, my test case fails giving the error 'Cannot read property subscribe of undefined' (for the first line inside foo function).
I have tried using mockservice classes too but the same error comes up. What is the possible reason for this and how can I solve it?