Skip to content

Commit

Permalink
test(material/dialog): Open dialogs inside NgZone (#29205)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba authored Jun 6, 2024
1 parent e3abc65 commit faf82b1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/material/dialog/testing/dialog-opener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
ChangeDetectionStrategy,
Component,
NgModule,
NgZone,
OnDestroy,
ViewEncapsulation,
inject,
} from '@angular/core';
import {MatDialog, MatDialogConfig, MatDialogModule, MatDialogRef} from '@angular/material/dialog';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -41,6 +43,8 @@ export class MatTestDialogOpener<T = unknown, R = unknown> implements OnDestroy

private readonly _afterClosedSubscription: Subscription;

private readonly _ngZone = inject(NgZone);

/** Static method that prepares this class to open the provided component. */
static withComponent<T = unknown, R = unknown>(
component: ComponentType<T>,
Expand All @@ -56,9 +60,11 @@ export class MatTestDialogOpener<T = unknown, R = unknown> implements OnDestroy
throw new Error(`MatTestDialogOpener does not have a component provided.`);
}

this.dialogRef = this.dialog.open<T, R>(
MatTestDialogOpener.component as ComponentType<T>,
MatTestDialogOpener.config || {},
this.dialogRef = this._ngZone.run(() =>
this.dialog.open<T, R>(
MatTestDialogOpener.component as ComponentType<T>,
MatTestDialogOpener.config || {},
),
);
this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {
this.closedResult = result;
Expand Down

0 comments on commit faf82b1

Please sign in to comment.