mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(dialog): complete injectable streams on destroy (#14254)
Fixes a couple of the streams on `MatDialog` not being completed when the provider is destroyed.
This commit is contained in:
committed by
Jeremy Elbourn
parent
9fa3376dc4
commit
e673608476
@@ -651,6 +651,23 @@ describe('MatDialog', () => {
|
||||
expect(overlayContainerElement.querySelectorAll('mat-dialog-container').length).toBe(0);
|
||||
}));
|
||||
|
||||
it('should complete open and close streams when the injectable is destroyed', fakeAsync(() => {
|
||||
const afterOpenedSpy = jasmine.createSpy('after opened spy');
|
||||
const afterAllClosedSpy = jasmine.createSpy('after all closed spy');
|
||||
const afterOpenedSubscription = dialog.afterOpened.subscribe({complete: afterOpenedSpy});
|
||||
const afterAllClosedSubscription = dialog.afterAllClosed.subscribe({
|
||||
complete: afterAllClosedSpy
|
||||
});
|
||||
|
||||
dialog.ngOnDestroy();
|
||||
|
||||
expect(afterOpenedSpy).toHaveBeenCalled();
|
||||
expect(afterAllClosedSpy).toHaveBeenCalled();
|
||||
|
||||
afterOpenedSubscription.unsubscribe();
|
||||
afterAllClosedSubscription.unsubscribe();
|
||||
}));
|
||||
|
||||
it('should allow the consumer to disable closing a dialog on navigation', fakeAsync(() => {
|
||||
dialog.open(PizzaMsg);
|
||||
dialog.open(PizzaMsg, {closeOnNavigation: false});
|
||||
|
||||
@@ -171,6 +171,8 @@ export class MatDialog implements OnDestroy {
|
||||
// Only close the dialogs at this level on destroy
|
||||
// since the parent service may still be active.
|
||||
this._closeDialogs(this._openDialogsAtThisLevel);
|
||||
this._afterAllClosedAtThisLevel.complete();
|
||||
this._afterOpenedAtThisLevel.complete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user