Skip to content

Commit 300b6d5

Browse files
devversionmmalerba
authored andcommitted
fix(select): remove selection if option is removed (#2560)
* fix(select): remove selection if option is removed * Currenty when an option is selected and the option is somehow programmatically removed the select updates its options. Right now it does not remove the selection if the selection has been removed from the options. Fixes #2524 * Update spec name * Remove check logic and just keep test * Update expectation message * Fix linting * Wait for zone to be stable
1 parent a494c92 commit 300b6d5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/lib/select/select.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,28 @@ describe('MdSelect', () => {
180180
expect(optionInstances[2].selected).toBe(false);
181181
});
182182

183+
it('should remove selection if option has been removed', async(() => {
184+
let select = fixture.componentInstance.select;
185+
186+
trigger.click();
187+
fixture.detectChanges();
188+
189+
let firstOption = overlayContainerElement.querySelectorAll('md-option')[0] as HTMLElement;
190+
191+
firstOption.click();
192+
fixture.detectChanges();
193+
194+
expect(select.selected).toBe(select.options.first, 'Expected first option to be selected.');
195+
196+
fixture.componentInstance.foods = [];
197+
fixture.detectChanges();
198+
199+
fixture.whenStable().then(() => {
200+
expect(select.selected)
201+
.toBe(null, 'Expected selection to be removed when option no longer exists.');
202+
});
203+
}));
204+
183205
it('should display the selected option in the trigger', () => {
184206
trigger.click();
185207
fixture.detectChanges();

0 commit comments

Comments
 (0)