Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/zone.js/lib/zone-spec/fake-async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {ZoneType} from '../zone-impl';
import {type ProxyZoneSpec} from './proxy';
import {throwProxyZoneError, type ProxyZoneSpec} from './proxy';

const global: any =
(typeof window === 'object' && window) || (typeof self === 'object' && self) || globalThis.global;
Expand Down Expand Up @@ -954,10 +954,7 @@ export function fakeAsync(fn: Function, options: {flush?: boolean} = {}): (...ar
const fakeAsyncFn: any = function (this: unknown, ...args: any[]) {
const ProxyZoneSpec = getProxyZoneSpec();
if (!ProxyZoneSpec) {
throw new Error(
'ProxyZoneSpec is needed for the fakeAsync() test helper but could not be found. ' +
'Make sure that your environment includes zone-testing.js',
);
throwProxyZoneError();
}
const proxyZoneSpec = ProxyZoneSpec.assertPresent();
if (Zone.current.get('FakeAsyncTestZoneSpec')) {
Expand Down
16 changes: 16 additions & 0 deletions packages/zone.js/lib/zone-spec/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@

import {ZoneType} from '../zone-impl';

declare let jest: any;

export function throwProxyZoneError(): never {
const jestPatched = typeof jest !== 'undefined' && jest['__zone_patch__'];
if (jestPatched) {
throw new Error(
'Only globals are patched with zone-testing. If you import `it`, `describe`, etc. directly, you cannot use `fakeAsync` or `waitForAsync`.',
);
} else {
throw new Error(
'ProxyZoneSpec is needed for the fakeAsync and waitForAsync test helpers but could not be found. ' +
'Make sure that your environment includes zone-testing.js',
);
}
}

export class ProxyZoneSpec implements ZoneSpec {
name: string = 'ProxyZone';

Expand Down