On the angular documentation I see these two functions, tick()
and flush()
. Both of these seem to do similar things. From the angular documentation, it says for tick:
Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
and for flush:
Simulates the asynchronous passage of time for the timers in the fakeAsync zone by draining the macrotask queue until it is empty. The returned value is the milliseconds of time that would have been elapsed.
Can anyone explain the difference to me?
EDIT (answered in the comments):
In addition, in the angular documentation tick()
is used without parameters, and the comment on that line even uses the phrase "flush"
it('should display error when TwainService fails', fakeAsync(() => {
// tell spy to return an error observable
getQuoteSpy.and.returnValue(
throwError('TwainService test failure'));
fixture.detectChanges(); // onInit()
// sync spy errors immediately after init
tick(); // flush the component's setTimeout()
fixture.detectChanges(); // update errorMessage within setTimeout()
expect(errorMessage()).toMatch(/test failure/, 'should display error');
expect(quoteEl.textContent).toBe('...', 'should show placeholder');
}));