Skip to main content

Choosing your approach

Ngx-testbox provides two approaches for stabilizing Angular tests. This page helps you decide which one to use.


Recommendation

Use the async/await approach for all new tests.

It is simpler, works with or without zone.js, and aligns with the direction of modern Angular.

If your app is zoneless, the async/await approach is the only supported choice. See Zoneless →.

info

The async/await approach can run in both zoneful and zoneless Angular applications. You do not need to be on zoneless to adopt it.


Comparison

FeatureAsync/await (recommended)fakeAsync
Entry pointrunTasksUntilStableAsyncrunTasksUntilStable
Test wrapperasync () => { ... }fakeAsync(() => { ... })
Timer modelReal time or fake timer callbackVirtual time via tick()
Response gettersSync or async (Promise)Sync only
HTTP instructions helperpredefinedHttpCallInstructionsAsyncpredefinedHttpCallInstructions
Zone.js supportWorks with or without zone.jsRequires zone.js
Error on timeoutLongRunningComponentErrorMaximumAttemptsToStabilizeFixtureReachedError
Preferred forNew code, zoneless apps, modern AngularLegacy zoneful apps, strict virtual time control

When to choose async/await

  • You are writing new tests.
  • Your app is zoneless or migrating toward zoneless.
  • You want your response getters to perform async work (e.g. reading JSON files, awaiting helpers).
  • You prefer async/await over fakeAsync / tick().
  • You want delayed work to be handled in a way that matches zoneless Angular (work with both zoneless and zone-based).

See Async approach →


When to choose fakeAsync

  • You are maintaining an existing test suite that already relies on fakeAsync.
  • You need deterministic virtual time manipulation via tick().
  • Your application requires zone.js and you are not ready to adopt the async pattern yet.

See Sync approach →


Can I mix both in the same project?

Yes. Each test can independently choose whichever approach fits best. However, for consistency within a single spec file it is recommended to pick one.