Skip to content

Commit faf82b1

Browse files
authored
test(material/dialog): Open dialogs inside NgZone (#29205)
1 parent e3abc65 commit faf82b1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/material/dialog/testing/dialog-opener.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import {
1111
ChangeDetectionStrategy,
1212
Component,
1313
NgModule,
14+
NgZone,
1415
OnDestroy,
1516
ViewEncapsulation,
17+
inject,
1618
} from '@angular/core';
1719
import {MatDialog, MatDialogConfig, MatDialogModule, MatDialogRef} from '@angular/material/dialog';
1820
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
@@ -41,6 +43,8 @@ export class MatTestDialogOpener<T = unknown, R = unknown> implements OnDestroy
4143

4244
private readonly _afterClosedSubscription: Subscription;
4345

46+
private readonly _ngZone = inject(NgZone);
47+
4448
/** Static method that prepares this class to open the provided component. */
4549
static withComponent<T = unknown, R = unknown>(
4650
component: ComponentType<T>,
@@ -56,9 +60,11 @@ export class MatTestDialogOpener<T = unknown, R = unknown> implements OnDestroy
5660
throw new Error(`MatTestDialogOpener does not have a component provided.`);
5761
}
5862

59-
this.dialogRef = this.dialog.open<T, R>(
60-
MatTestDialogOpener.component as ComponentType<T>,
61-
MatTestDialogOpener.config || {},
63+
this.dialogRef = this._ngZone.run(() =>
64+
this.dialog.open<T, R>(
65+
MatTestDialogOpener.component as ComponentType<T>,
66+
MatTestDialogOpener.config || {},
67+
),
6268
);
6369
this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {
6470
this.closedResult = result;

0 commit comments

Comments
 (0)