function
Wraps a function to be executed in the fakeAsync
zone:
flushMicrotasks()
.tick()
simulates the asynchronous passage of time.fakeAsync(fn: Function): (...args: any[]) => any
fn | Function | The function that you want to wrap in the |
(...args: any[]) => any
: The function wrapped to be executed in the fakeAsync
zone. Any arguments passed when calling this returned function will be passed through to the fn
function in the parameters when it is called.
If there are any pending timers at the end of the function, an exception is thrown.
Can be used to wrap inject()
calls.
Further information is available in the Usage Notes...
describe('this test', () => { it('looks async but is synchronous', <any>fakeAsync((): void => { let flag = false; setTimeout(() => { flag = true; }, 100); expect(flag).toBe(false); tick(50); expect(flag).toBe(false); tick(50); expect(flag).toBe(true); })); });
© 2010–2021 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v12.angular.io/api/core/testing/fakeAsync