Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstalliTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Angular’s Zone.js testing utilities help control asynchronous work in unit tests: use waitForAsync when a test should finish after tracked work completes, and use fakeAsync with tick() when a Zone.js-based test needs explicit control over simulated time. However, Angular no longer recommends fakeAsync for new tests; its current guidance favors native async testing or test-runner fake timers such as Vitest’s.
What are Angular’s Zone.js testing utilities?
They are helpers for managing asynchronous behavior in tests that use Zone.js. Angular groups waitForAsync, fakeAsync, tick(), flushMicrotasks(), and discardPeriodicTasks() among its Zone.js testing utilities. They address different needs: tracking when asynchronous work is done, or controlling when queued work and timers run. See Angular’s Zone.js Testing Utilities guide.
These helpers are separate from general testing APIs such as TestBed and ComponentFixture, which Angular documents for configuring tests and working with component fixtures in its Testing utility APIs guide.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →How do waitForAsync and fakeAsync differ?
| Approach | How it handles asynchronous work | Best fit |
|---|---|---|
waitForAsync |
Tracks asynchronous calls in an asynchronous test zone and completes the test when those calls finish. It does not provide explicit virtual-time control. | A test that should wait for tracked asynchronous work to finish without manually advancing a clock. |
fakeAsync |
Runs the test body in a special fake-async zone. Use flushMicrotasks() for pending microtasks and tick() to advance simulated time and process timers. |
An existing or specialized Zone.js test that must assert behavior at specific points as timers or microtasks run. |
Angular documents the behavior of waitForAsync and fakeAsync in their API references. Choose based on what the test needs to observe: eventual completion, or a particular state before and after queued work runs.
#1 Best Overall
How do I use tick() in an Angular test?
tick(millis?) advances simulated time inside a fakeAsync test and processes timer and microtask queues. It can only be called within the fakeAsync zone. Use it when an assertion depends on a timer having elapsed, rather than relying on real waiting.
import { fakeAsync, tick } from '@angular/core/testing';
it('updates after the timer elapses', fakeAsync(() => {
// Start the operation that schedules a timer.
startDelayedUpdate();
tick(500);
expect(readUpdate()).toBe('complete');
}));
The operation and expected value in this example are illustrative; substitute the behavior your test exercises. The important constraint is that tick() belongs inside a fakeAsync test. Angular’s Zone.js Testing Utilities guide describes advancing time and processing queued work.
Rank #2
How do flushMicrotasks() and discardPeriodicTasks() fit in?
Run pending microtasks
Call flushMicrotasks() from within a fakeAsync test to run pending microtasks without advancing simulated time. This is useful when the test needs to settle queued microtask work before checking an assertion.
Clean up intentional periodic work
Intervals and other periodic tasks can remain pending by design. Call discardPeriodicTasks() to clear periodic tasks created in the fake-async zone when they are intentionally left running. Otherwise, structure the test so it does not leave unexpected queued work behind. Angular documents both helpers in the Zone.js Testing Utilities guide.
Rank #3
Is fakeAsync still recommended?
No—not as the default choice for new tests. Angular’s component-testing guide states, “The use of fakeAsync is no longer recommended,” and advises: “Prefer using native async testing strategies or other fake timers (also called mock clocks) like those from Vitest or Jasmine.” See Component testing scenarios.
This is guidance for choosing an approach, not a requirement to immediately rewrite every existing test. fakeAsync remains relevant when maintaining Zone.js-based tests or when a specific test benefits from its virtual-time controls. For new tests, start with native async patterns or the fake timers provided by the project’s runner.
Rank #4
Can I use fakeAsync with Vitest?
Not directly as an unmodified Zone.js helper. Angular’s Vitest migration guide documents a compatibility patch: adding zone.js/plugins/vitest-patch to the test target’s polyfills can enable helpers such as fakeAsync, flush, and waitForAsync, or allow existing tests using them to work. Consult Migrating from Karma to Vitest for the setup details applicable to your project.
Angular also recommends planning a conversion toward native async tests and Vitest fake timers. The patch is a compatibility option for existing suites, not a reason to assume that every Zone.js testing pattern is the preferred Vitest approach.
Quick Recap
How should I choose an approach?
- Need the test to finish when tracked asynchronous calls complete? Consider
waitForAsync. - Need to assert an intermediate state around a timer or microtask? In an existing or specialized Zone.js test,
fakeAsyncwithtick()orflushMicrotasks()provides explicit control. - Writing a new test? Follow Angular’s current preference for native async strategies or fake timers from your test runner.
- Using Vitest with existing Zone.js tests? Follow Angular’s documented
zone.js/plugins/vitest-patchsetup, and plan migration toward native async and Vitest fake timers.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

