Skip to content

Commit

Permalink
fix(dialog): complete injectable streams on destroy (angular#14254)
Browse files Browse the repository at this point in the history
Fixes a couple of the streams on `MatDialog` not being completed when the provider is destroyed.
  • Loading branch information
crisbeto authored and josephperrott committed Jan 14, 2019
1 parent 8eb9b1f commit 2bc40f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 2 additions & 0 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 2bc40f5

Please sign in to comment.