I'm trying to mock a function call using spyOn and callFake, but the real function is still being called instead of the fake function.
component code:
async getOrderProfile() {
let ordersSuccess = false;
...
try {
const ordersResponse = await this.ordersService.getOrderProfile(params);
ordersSuccess = this.validateResponse(ordersResponse);
...
} catch (error) {
...
}
}
spec:
describe('OrdersComponent', () => {
let component: OrdersComponent;
let fixture: ComponentFixture<OrdersComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [OrdersComponent],
imports: [],
providers: []
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(OrdersComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should call getOrdersNoteData', () => {
...
spyOn(component, 'validateResponse').and.callFake(() => {
console.log('faked method');
return true;
});
component.getOrderProfile();
...
});
});
I don't see my test statement logged to the console, and the real function is throwing an error because it doesn't have all the expected data. I'm not sure what I'm doing wrong on this.
I've also used spyOn returnValue with no luck:
spyOn(component, 'validateResponse').and.returnValue(true)