@@ -56,7 +56,8 @@ describe('MdSelect', () => {
56
56
BasicSelectInitiallyHidden ,
57
57
BasicSelectNoPlaceholder ,
58
58
BasicSelectWithTheming ,
59
- ResetValuesSelect
59
+ ResetValuesSelect ,
60
+ FalsyValueSelect
60
61
] ,
61
62
providers : [
62
63
{ provide : OverlayContainer , useFactory : ( ) => {
@@ -449,6 +450,22 @@ describe('MdSelect', () => {
449
450
expect ( fixture . componentInstance . select . selected ) . not . toBeDefined ( ) ;
450
451
} ) ;
451
452
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
+
452
469
} ) ;
453
470
454
471
describe ( 'forms integration' , ( ) => {
@@ -2504,3 +2521,20 @@ class ResetValuesSelect {
2504
2521
2505
2522
@ViewChild ( MdSelect ) select : MdSelect ;
2506
2523
}
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