Skip to content

Commit a79e133

Browse files
committed
fix tests
1 parent b875350 commit a79e133

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/material/dialog/dialog-container.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
9494
/** Current timer for dialog animations. */
9595
private _animationTimer: ReturnType<typeof setTimeout> | null = null;
9696

97+
private _isDestroyed = false;
98+
9799
constructor(
98100
elementRef: ElementRef,
99101
focusTrapFactory: FocusTrapFactory,
@@ -262,6 +264,10 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
262264
* be called by sub-classes that use different animation implementations.
263265
*/
264266
protected _openAnimationDone(totalTime: number) {
267+
if (this._isDestroyed) {
268+
return;
269+
}
270+
265271
if (this._config.delayFocusTrap) {
266272
this._trapFocus();
267273
}
@@ -275,6 +281,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
275281
if (this._animationTimer !== null) {
276282
clearTimeout(this._animationTimer);
277283
}
284+
285+
this._isDestroyed = true;
278286
}
279287

280288
override attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {

src/material/dialog/dialog.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
inject,
4141
TestBed,
4242
tick,
43+
waitForAsync,
4344
} from '@angular/core/testing';
4445
import {By} from '@angular/platform-browser';
4546
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
@@ -965,7 +966,8 @@ describe('MDC-based MatDialog', () => {
965966
dialog.open(PizzaMsg, {disableClose: true, viewContainerRef: testViewContainerRef});
966967

967968
viewContainerFixture.detectChanges();
968-
flushMicrotasks();
969+
flush();
970+
viewContainerFixture.detectChanges();
969971

970972
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
971973
let input = overlayContainerElement.querySelector('input') as HTMLInputElement;
@@ -994,7 +996,8 @@ describe('MDC-based MatDialog', () => {
994996
});
995997

996998
viewContainerFixture.detectChanges();
997-
flushMicrotasks();
999+
flush();
1000+
viewContainerFixture.detectChanges();
9981001

9991002
let backdrop = overlayContainerElement.querySelector(
10001003
'.cdk-overlay-backdrop',
@@ -1179,7 +1182,8 @@ describe('MDC-based MatDialog', () => {
11791182
dialog.open(PizzaMsg, {viewContainerRef: testViewContainerRef});
11801183

11811184
viewContainerFixture.detectChanges();
1182-
flushMicrotasks();
1185+
flush();
1186+
viewContainerFixture.detectChanges();
11831187

11841188
expect(document.activeElement!.tagName)
11851189
.withContext('Expected first tabbable element (input) in the dialog to be focused.')
@@ -1505,7 +1509,8 @@ describe('MDC-based MatDialog', () => {
15051509
dialog.open(DialogWithoutFocusableElements);
15061510

15071511
viewContainerFixture.detectChanges();
1508-
flushMicrotasks();
1512+
flush();
1513+
viewContainerFixture.detectChanges();
15091514

15101515
expect(document.activeElement!.tagName)
15111516
.withContext('Expected dialog container to be focused.')

0 commit comments

Comments
 (0)