Function within setTimout has not been called in Unit Test
I trying to test an angular 10 function that call another function within a setTimeout. I am using Karma and Jasmine but I can get to pass the test. I read a lot of examples on blog post, angular documentation and even here in stackoverflow and all points me to this solution:
MY METHOD
loadDefault() {
... do something
setTimeout(() => this.run());
}
MY UNIT TEST
describe('loadDefault', () => {
it('should call run function after ...', fakeAsync(() => {
const spyRun = spyOn(component, 'run').and.callFake(fakeFn);
component.loadDefault()
fixture.detectChanges()
expect(spyRun).toHaveBeenCalled()
}))
});
When karma runs shows me those resuls:
Can you help me identifying whats going wrong?
Source: Angular Questions