From 403a3d1ca238843d13da189dd478dfe26f1eceb2 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 24 Apr 2020 16:23:28 +0200 Subject: [PATCH] fix(tree): complete viewChange stream on destroy (#18991) Fixes the tree not completing its `viewChange` stream. --- src/cdk/tree/tree.spec.ts | 12 ++++++++++++ src/cdk/tree/tree.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/src/cdk/tree/tree.spec.ts b/src/cdk/tree/tree.spec.ts index 720d21ed6027..cff2df597175 100644 --- a/src/cdk/tree/tree.spec.ts +++ b/src/cdk/tree/tree.spec.ts @@ -71,6 +71,18 @@ describe('CdkTree', () => { expect(!!CdkTreeNode.mostRecentTreeNode).toBe(false); }); + it('should complete the viewChange stream on destroy', () => { + configureCdkTreeTestingModule([SimpleCdkTreeApp]); + const fixture = TestBed.createComponent(SimpleCdkTreeApp); + fixture.detectChanges(); + const spy = jasmine.createSpy('completeSpy'); + const subscription = fixture.componentInstance.tree.viewChange.subscribe({complete: spy}); + + fixture.destroy(); + expect(spy).toHaveBeenCalled(); + subscription.unsubscribe(); + }); + describe('flat tree', () => { describe('should initialize', () => { let fixture: ComponentFixture; diff --git a/src/cdk/tree/tree.ts b/src/cdk/tree/tree.ts index cecba944795b..585e3734cf5e 100644 --- a/src/cdk/tree/tree.ts +++ b/src/cdk/tree/tree.ts @@ -140,6 +140,7 @@ export class CdkTree implements AfterContentChecked, CollectionViewer, OnDest ngOnDestroy() { this._nodeOutlet.viewContainer.clear(); + this.viewChange.complete(); this._onDestroy.next(); this._onDestroy.complete();