@@ -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 : ( ) => {
@@ -621,6 +622,22 @@ describe('MdSelect', () => {
621
622
. toContain ( '*' , `Expected placeholder to have an asterisk, as control was required.` ) ;
622
623
} ) ;
623
624
625
+ it ( 'should be able to programmatically select a falsy option' , ( ) => {
626
+ fixture . destroy ( ) ;
627
+
628
+ const falsyFixture = TestBed . createComponent ( FalsyValueSelect ) ;
629
+
630
+ falsyFixture . detectChanges ( ) ;
631
+ falsyFixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
632
+ falsyFixture . componentInstance . control . setValue ( 0 ) ;
633
+ falsyFixture . detectChanges ( ) ;
634
+
635
+ expect ( falsyFixture . componentInstance . options . first . selected )
636
+ . toBe ( true , 'Expected first option to be selected' ) ;
637
+ expect ( overlayContainerElement . querySelectorAll ( 'md-option' ) [ 0 ] . classList )
638
+ . toContain ( 'mat-selected' , 'Expected first option to be selected' ) ;
639
+ } ) ;
640
+
624
641
} ) ;
625
642
626
643
describe ( 'disabled behavior' , ( ) => {
@@ -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