Skip to content

Commit 46411e3

Browse files
amcdnlandrewseguin
authored andcommitted
fix(select): complete state change event (#8777)
* fix(select): complete state change event * chore: add event test
1 parent b2370ce commit 46411e3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/lib/select/select.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,25 @@ describe('MatSelect', () => {
17781778
}));
17791779
});
17801780

1781+
describe('change events', () => {
1782+
beforeEach(async(() => configureMatSelectTestingModule([SelectWithPlainTabindex])));
1783+
1784+
it('should complete the stateChanges stream on destroy', () => {
1785+
const fixture = TestBed.createComponent(SelectWithPlainTabindex);
1786+
fixture.detectChanges();
1787+
1788+
const debugElement = fixture.debugElement.query(By.directive(MatSelect));
1789+
const select = debugElement.componentInstance;
1790+
1791+
const spy = jasmine.createSpy('stateChanges complete');
1792+
const subscription = select.stateChanges.subscribe(undefined, undefined, spy);
1793+
1794+
fixture.destroy();
1795+
expect(spy).toHaveBeenCalled();
1796+
subscription.unsubscribe();
1797+
});
1798+
});
1799+
17811800
describe('when initially hidden', () => {
17821801
beforeEach(async(() => configureMatSelectTestingModule([BasicSelectInitiallyHidden])));
17831802

src/lib/select/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
509509
ngOnDestroy() {
510510
this._destroy.next();
511511
this._destroy.complete();
512+
this.stateChanges.complete();
512513
}
513514

514515
/** Toggles the overlay panel open or closed. */

0 commit comments

Comments
 (0)