@@ -4329,6 +4329,32 @@ describe('MatSelect', () => {
43294329 }).not.toThrow();
43304330 }));
43314331
4332+ it('should be able to programmatically set an array with duplicate values', fakeAsync(() => {
4333+ testInstance.foods = [
4334+ { value: 'steak-0', viewValue: 'Steak' },
4335+ { value: 'pizza-1', viewValue: 'Pizza' },
4336+ { value: 'pizza-1', viewValue: 'Pizza' },
4337+ { value: 'pizza-1', viewValue: 'Pizza' },
4338+ { value: 'pizza-1', viewValue: 'Pizza' },
4339+ { value: 'pizza-1', viewValue: 'Pizza' },
4340+ ];
4341+ fixture.detectChanges();
4342+ testInstance.control.setValue(['steak-0', 'pizza-1', 'pizza-1', 'pizza-1']);
4343+ fixture.detectChanges();
4344+
4345+ trigger.click();
4346+ fixture.detectChanges();
4347+
4348+ const optionNodes = Array.from(overlayContainerElement.querySelectorAll('mat-option'));
4349+ const optionInstances = testInstance.options.toArray();
4350+
4351+ expect(optionNodes.map(node => node.classList.contains('mat-selected')))
4352+ .toEqual([true, true, true, true, false, false]);
4353+
4354+ expect(optionInstances.map(instance => instance.selected))
4355+ .toEqual([true, true, true, true, false, false]);
4356+ }));
4357+
43324358 });
43334359});
43344360
0 commit comments