Skip to content
Merged
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: 7 additions & 0 deletions src/cdk/testing/testbed/task-state-zone-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export class TaskStateZoneInterceptor {
return {stable: !state.macroTask && !state.microTask};
}

static isInProxyZone(): boolean {
if (typeof Zone === 'undefined') {
return false;
}
return ((Zone as any)['ProxyZoneSpec'] as ProxyZoneStatic | undefined)?.get() !== undefined;
}

/**
* Sets up the custom task state Zone interceptor in the `ProxyZone`. Throws if
* no `ProxyZone` could be found.
Expand Down
5 changes: 4 additions & 1 deletion src/cdk/testing/testbed/testbed-harness-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
) {
super(rawRootElement);
this._options = {...defaultEnvironmentOptions, ...options};
if (typeof Zone !== 'undefined') {
if (TaskStateZoneInterceptor.isInProxyZone()) {
this._taskState = TaskStateZoneInterceptor.setup();
}
this._stabilizeCallback = () => this.forceStabilize();
Expand Down Expand Up @@ -178,6 +178,9 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
/**
* Waits for all scheduled or running async tasks to complete. This allows harness
* authors to wait for async tasks outside of the Angular zone.
*
* This only works when Zone.js is present _and_ patches are applied to the test framework
* by `zone.js/testing` (Jasmine and Jest only) or another script.
*/
async waitForTasksOutsideAngular(): Promise<void> {
// If we run in the fake async zone, we run "flush" to run any scheduled tasks. This
Expand Down
Loading