Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Angular’s Zone.js testing utilities help tests manage asynchronous work: waitForAsync waits for tracked work to finish, while fakeAsync lets a test advance a simulated clock with tick(). Angular now says fakeAsync is no longer recommended for new tests; prefer native async strategies or your test runner’s fake timers. Existing Zone.js suites can still use it, with extra setup required for Vitest.
What are Angular’s Zone.js testing utilities?
They are helpers for controlling asynchronous work in unit tests that use Zone.js. They let a test either wait for asynchronous activity to complete or run selected work against a simulated clock. They are specific to Zone.js-based testing, not general substitutes for Angular’s TestBed or ComponentFixture, which handle test setup and component fixture work. See Angular’s testing utility APIs.
As an Amazon Associate I earn from qualifying purchases.
How do you choose between waitForAsync and fakeAsync?
| Approach | How it handles asynchronous work | Best fit |
|---|---|---|
waitForAsync |
Tracks asynchronous calls in its test zone and completes the test when those calls finish. | Tests that need to wait for tracked work, without manually advancing time. |
fakeAsync |
Runs the test in a special zone where you can run microtasks and advance simulated time. | Existing or specialized Zone.js tests that must assert what happens at particular points around timers or microtasks. |
| Native async or runner fake timers | Uses native asynchronous patterns or the test runner’s mock-clock facilities. | Angular’s currently preferred approach for new tests. |
The practical distinction is whether the test should finish when tracked work completes, or whether it needs to control when asynchronous work runs. Also consider the project’s runtime and runner: Zone.js-specific helpers are not directly interchangeable with the fake timers provided by Vitest or Jasmine. Angular’s Zone.js utilities guide and component-testing guidance cover these approaches.
Free tools Windows power users keep installed
One-click scans. No signup required.
What is waitForAsync in Angular?
waitForAsync(fn) wraps a test function in an asynchronous test zone and returns a callback-style function. The zone tracks asynchronous calls; the test completes after that tracked work finishes. This is useful when the test needs to wait for asynchronous setup or behavior, but does not need to choose an exact simulated time for timers to fire. See the waitForAsync API reference.
#1 Best Overall
What is fakeAsync in Angular?
fakeAsync(fn, options?) runs a function inside a fake-async zone. Within it, flushMicrotasks() runs pending microtasks, and tick(millis?) advances simulated time while processing timer and microtask queues. Use these controls when an existing or specialized Zone.js test needs to inspect intermediate states—for example, before and after a timer would fire.
The flush option controls how the macrotask queue is handled after the test: it can drain that queue, or pending timers can cause an exception. Check the fakeAsync API reference for the option’s current API details. Unexpected queued work should not be left behind at the end of a test.
Rank #2
How do you use tick() in an Angular test?
Call tick() only inside a fakeAsync test. It advances the simulated clock by the requested number of milliseconds (or by the default interval when omitted) and processes timer and microtask queues within that fake-async zone. It does not make wall-clock time pass.
import { fakeAsync, tick } from '@angular/core/testing';
it('runs a timer after simulated time advances', fakeAsync(() => {
let complete = false;
setTimeout(() => {
complete = true;
}, 100);
tick(100);
expect(complete).toBe(true);
}));
Use flushMicrotasks() when the work to run is pending microtasks rather than a timer delay. Periodic work, such as an interval, can be removed with discardPeriodicTasks() when it is intentionally still pending; do not use it to conceal unexpected queued work. The available helpers are documented in Angular’s Zone.js testing utilities guide.
Rank #3
Can you use fakeAsync with Vitest?
fakeAsync requires Zone.js and is not directly usable with Vitest by default. Angular documents a compatibility patch for existing Zone.js tests: add zone.js/plugins/vitest-patch to the test target’s polyfills. This can enable helpers such as fakeAsync, flush, and waitForAsync in that setup.
Angular’s Vitest migration guide presents the patch as a way to support existing tests, while recommending a plan to convert them to native async patterns and Vitest fake timers. Consult the Angular Karma-to-Vitest migration guide for the project configuration and migration context.
Rank #4
What does Angular recommend for new tests?
Angular’s component-testing guide states: “The use of fakeAsync is no longer recommended.” It advises: “Prefer using native async testing strategies or other fake timers (also called mock clocks) like those from Vitest or Jasmine.” That is current guidance, not a requirement to immediately rewrite every existing Zone.js test. Keep legacy tests working where needed, but use native async or runner-provided fake timers as the direction for new work.
Recommended Free Tools
Quick Recap
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.




