Skip to content

Commit d7d3be1

Browse files
crisbetojelbourn
authored andcommitted
fix(tree): complete viewChange stream on destroy (#18991)
Fixes the tree not completing its `viewChange` stream.
1 parent 95059d4 commit d7d3be1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/cdk/tree/tree.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ describe('CdkTree', () => {
7171
expect(!!CdkTreeNode.mostRecentTreeNode).toBe(false);
7272
});
7373

74+
it('should complete the viewChange stream on destroy', () => {
75+
configureCdkTreeTestingModule([SimpleCdkTreeApp]);
76+
const fixture = TestBed.createComponent(SimpleCdkTreeApp);
77+
fixture.detectChanges();
78+
const spy = jasmine.createSpy('completeSpy');
79+
const subscription = fixture.componentInstance.tree.viewChange.subscribe({complete: spy});
80+
81+
fixture.destroy();
82+
expect(spy).toHaveBeenCalled();
83+
subscription.unsubscribe();
84+
});
85+
7486
describe('flat tree', () => {
7587
describe('should initialize', () => {
7688
let fixture: ComponentFixture<SimpleCdkTreeApp>;

src/cdk/tree/tree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest
140140
ngOnDestroy() {
141141
this._nodeOutlet.viewContainer.clear();
142142

143+
this.viewChange.complete();
143144
this._onDestroy.next();
144145
this._onDestroy.complete();
145146

0 commit comments

Comments
 (0)