diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index b609b414894..83038234601 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -1778,6 +1778,25 @@ describe('MatSelect', () => { })); }); + describe('change events', () => { + beforeEach(async(() => configureMatSelectTestingModule([SelectWithPlainTabindex]))); + + it('should complete the stateChanges stream on destroy', () => { + const fixture = TestBed.createComponent(SelectWithPlainTabindex); + fixture.detectChanges(); + + const debugElement = fixture.debugElement.query(By.directive(MatSelect)); + const select = debugElement.componentInstance; + + const spy = jasmine.createSpy('stateChanges complete'); + const subscription = select.stateChanges.subscribe(undefined, undefined, spy); + + fixture.destroy(); + expect(spy).toHaveBeenCalled(); + subscription.unsubscribe(); + }); + }); + describe('when initially hidden', () => { beforeEach(async(() => configureMatSelectTestingModule([BasicSelectInitiallyHidden]))); diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index a0e9df39e8f..778f16bc876 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -509,6 +509,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, ngOnDestroy() { this._destroy.next(); this._destroy.complete(); + this.stateChanges.complete(); } /** Toggles the overlay panel open or closed. */