angular/angular · error · Error

ProxyZoneSpec is needed for the withProxyZone() test helper

Error message

ProxyZoneSpec is needed for the withProxyZone() test helper but could not be found. Make sure that your environment includes zone-testing.js

What it means

Error "ProxyZoneSpec is needed for the withProxyZone() test helper but could not be found. Make sure that your environment includes zone-testing.js" thrown in angular/angular.

Source

Thrown at packages/zone.js/lib/zone-spec/fake-async-test.ts:1079

}

/**
 * Wraps a function to be executed in a shared ProxyZone.
 *
 * If no shared ProxyZone exists, one is created and reused for subsequent calls.
 * Useful for wrapping test setup (beforeEach) and test execution (it) when test
 * runner patching isn't available or desired for setting up the ProxyZone.
 *
 * @param fn The function to wrap.
 * @returns A function that executes the original function within the shared ProxyZone.
 *
 * @experimental
 */
export function withProxyZone<T extends Function>(fn: T): T {
  const autoProxyFn: any = function (this: unknown, ...args: any[]) {
    const proxyZoneSpec = getProxyZoneSpec();
    if (proxyZoneSpec === undefined) {
      throw new Error(
        'ProxyZoneSpec is needed for the withProxyZone() test helper but could not be found. ' +
          'Make sure that your environment includes zone-testing.js',
      );
    }

    const proxyZone = proxyZoneSpec.get() !== undefined ? Zone.current : getOrCreateRootProxy();
    return proxyZone.run(fn, this, args);
  };
  return autoProxyFn as T;
}

function getOrCreateRootProxy() {
  const ProxyZoneSpec = getProxyZoneSpec();
  if (ProxyZoneSpec === undefined) {
    throw new Error(
      'ProxyZoneSpec is needed for withProxyZone but could not be found. ' +
        'Make sure that your environment includes zone-testing.js',
    );

View on GitHub (pinned to 51cb07e980)

Solutions

  1. Include zone-testing.js (or zone.js/plugins/proxy) in the test environment setup.

When it happens

Trigger: Thrown at packages/zone.js/lib/zone-spec/fake-async-test.ts:1079 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of angular/angular@51cb07e980 (2026-08-22). Data as JSON: /api/errors/48114abac04254b0. Report an issue: GitHub.