@@ -56,7 +56,8 @@ describe('MdSelect', () => {
5656 BasicSelectInitiallyHidden ,
5757 BasicSelectNoPlaceholder ,
5858 BasicSelectWithTheming ,
59- ResetValuesSelect
59+ ResetValuesSelect ,
60+ FalsyValueSelect
6061 ] ,
6162 providers : [
6263 { provide : OverlayContainer , useFactory : ( ) => {
@@ -449,6 +450,22 @@ describe('MdSelect', () => {
449450 expect ( fixture . componentInstance . select . selected ) . not . toBeDefined ( ) ;
450451 } ) ;
451452
453+ it ( 'should be able to programmatically select a falsy option' , ( ) => {
454+ fixture . destroy ( ) ;
455+
456+ let falsyFixture = TestBed . createComponent ( FalsyValueSelect ) ;
457+
458+ falsyFixture . detectChanges ( ) ;
459+ falsyFixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
460+ falsyFixture . componentInstance . control . setValue ( 0 ) ;
461+ falsyFixture . detectChanges ( ) ;
462+
463+ expect ( falsyFixture . componentInstance . options . first . selected )
464+ . toBe ( true , 'Expected first option to be selected' ) ;
465+ expect ( overlayContainerElement . querySelectorAll ( 'md-option' ) [ 0 ] . classList )
466+ . toContain ( 'mat-selected' , 'Expected first option to be selected' ) ;
467+ } ) ;
468+
452469 } ) ;
453470
454471 describe ( 'forms integration' , ( ) => {
@@ -2504,3 +2521,20 @@ class ResetValuesSelect {
25042521
25052522 @ViewChild ( MdSelect ) select : MdSelect ;
25062523}
2524+
2525+
2526+ @Component ( {
2527+ template : `
2528+ <md-select [formControl]="control">
2529+ <md-option *ngFor="let food of foods" [value]="food.value">{{ food.viewValue }}</md-option>
2530+ </md-select>
2531+ `
2532+ } )
2533+ class FalsyValueSelect {
2534+ foods : any [ ] = [
2535+ { value : 0 , viewValue : 'Steak' } ,
2536+ { value : 1 , viewValue : 'Pizza' } ,
2537+ ] ;
2538+ control = new FormControl ( ) ;
2539+ @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
2540+ }
0 commit comments