I have a service that is calling a http function:
processLogin(info) {
return this._call.post('login', info).subscribe(response => {
if (response.status === 'success') {
this._auth.login(response.object);
return true;
}
return false;
}, error => {
return false;
});
}
And this is the test I'm trying to make:
describe('Facebook Login', () => {
let service: FacebookLoginService;
let call: CallService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
FacebookLoginService,
{ provide: CallService, useClass: CallServiceMock },
]
});
service = TestBed.get(FacebookLoginService);
call = TestBed.get(CallService);
});
it('should process the login when the post method return success', () => {
spyOn(call, 'post').and.returnValue(Observable.of({status: 'success'}));
service.processLogin('any').subscribe(response => {
console.log(response);
});
});
});
However, when I run the test I keep getting the error message
processLogin().subscribe( ... ) is not a function
And if I change the type of response mocked to anything but Observable.of, I get the error message
call.post.subscribe( ... ) is not a function
Why is it not wokirng? I have a very similar test on another service that also calls call.post() and it's working.