@@ -41,6 +41,7 @@ describe('MatChipList', () => {
4141 InputChipList ,
4242 MultiSelectionChipList ,
4343 FalsyValueChipList ,
44+ SelectedChipList
4445 ] ,
4546 providers : [ {
4647 provide : Directionality , useFactory : ( ) => {
@@ -63,6 +64,21 @@ describe('MatChipList', () => {
6364 } ) ;
6465 } ) ;
6566
67+ describe ( 'with selected chips' , ( ) => {
68+ beforeEach ( async ( ( ) => {
69+ fixture = TestBed . createComponent ( SelectedChipList ) ;
70+ fixture . detectChanges ( ) ;
71+ } ) ) ;
72+
73+ it ( 'should not override chips selected' , ( ) => {
74+ const instanceChips = fixture . componentInstance . chips . toArray ( ) ;
75+
76+ expect ( instanceChips [ 0 ] . selected ) . toBe ( true , 'Expected first option to be selected.' ) ;
77+ expect ( instanceChips [ 1 ] . selected ) . toBe ( false , 'Expected second option to be not selected.' ) ;
78+ expect ( instanceChips [ 2 ] . selected ) . toBe ( true , 'Expected third option to be selected.' ) ;
79+ } ) ;
80+ } ) ;
81+
6682 describe ( 'focus behaviors' , ( ) => {
6783 beforeEach ( async ( ( ) => {
6884 setupStandardList ( ) ;
@@ -1027,3 +1043,21 @@ class FalsyValueChipList {
10271043 control = new FormControl ( ) ;
10281044 @ViewChildren ( MatChip ) chips : QueryList < MatChip > ;
10291045}
1046+
1047+ @Component ( {
1048+ template : `
1049+ <mat-chip-list>
1050+ <mat-chip *ngFor="let food of foods" [value]="food.value" [selected]="food.selected">
1051+ {{ food.viewValue }}
1052+ </mat-chip>
1053+ </mat-chip-list>
1054+ `
1055+ } )
1056+ class SelectedChipList {
1057+ foods : any [ ] = [
1058+ { value : 0 , viewValue : 'Steak' , selected : true } ,
1059+ { value : 1 , viewValue : 'Pizza' , selected : false } ,
1060+ { value : 2 , viewValue : 'Pasta' , selected : true } ,
1061+ ] ;
1062+ @ViewChildren ( MdChip ) chips : QueryList < MdChip > ;
1063+ }
0 commit comments