I have a method in component.ts file, which is calling a service method.
The code structure is like as following-
getDetails(){
if(!alreadyCached){
callLogFunction();
}
this.service.getData()
.then(res => {
//rest of the logic here
})
.catch(err=>{ //catch logic here })
}
My test block looks like this-
it('should call service.getData', ()=>{
spyOn(service,'getData').and.returnValue(Promise.resolve([]);
component.getDetails();
fixture.whenStable().then(()=>{
expect(service.getData).toHaveBeenCalled();
}
}
Why am I getting error that expected spy getData to have been called
It would be great if you can help me with testing then and catch block (how to write tests for them)
Thanks! :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…