From 6b0d80e38d0fe6b2301293ee52e3fd127f1eaac0 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 22 May 2025 12:49:48 -0700 Subject: [PATCH] fix(core): Testing should not throw when Zone does not patch test FW APIs This prevents `core/testing` from throwing an error if ZoneJS is present but does not patch the test FW APIs such that `fakeAsync` works automatically. For example, there is currently no patching of the vitest APIs, so if you try to use Vitest with Zone on the page, it will throw. --- packages/core/testing/src/fake_async.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/testing/src/fake_async.ts b/packages/core/testing/src/fake_async.ts index 65aab4f6e0d5..a860b8709224 100644 --- a/packages/core/testing/src/fake_async.ts +++ b/packages/core/testing/src/fake_async.ts @@ -59,7 +59,7 @@ export function resetFakeAsyncZoneIfExists(): void { * @publicApi */ export function fakeAsync(fn: Function, options?: {flush?: boolean}): (...args: any[]) => any { - if (fakeAsyncTestModule) { + if (fakeAsyncTestModule && (Zone as any)['ProxyZoneSpec']?.isLoaded()) { return fakeAsyncTestModule.fakeAsync(fn, options); } throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);