Skip to content

Commit

Permalink
fix(tree): complete viewChange stream on destroy (angular#18991)
Browse files Browse the repository at this point in the history
Fixes the tree not completing its `viewChange` stream.
  • Loading branch information
crisbeto committed Apr 24, 2020
1 parent ed4e91d commit 403a3d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cdk/tree/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleCdkTreeApp>;
Expand Down
1 change: 1 addition & 0 deletions src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDest
ngOnDestroy() {
this._nodeOutlet.viewContainer.clear();

this.viewChange.complete();
this._onDestroy.next();
this._onDestroy.complete();

Expand Down

0 comments on commit 403a3d1

Please sign in to comment.