@@ -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 : ( ) => {
@@ -631,6 +632,22 @@ describe('MdSelect', () => {
631
632
. toContain ( '*' , `Expected placeholder to have an asterisk, as control was required.` ) ;
632
633
} ) ;
633
634
635
+ it ( 'should be able to programmatically select a falsy option' , ( ) => {
636
+ fixture . destroy ( ) ;
637
+
638
+ const falsyFixture = TestBed . createComponent ( FalsyValueSelect ) ;
639
+
640
+ falsyFixture . detectChanges ( ) ;
641
+ falsyFixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
642
+ falsyFixture . componentInstance . control . setValue ( 0 ) ;
643
+ falsyFixture . detectChanges ( ) ;
644
+
645
+ expect ( falsyFixture . componentInstance . options . first . selected )
646
+ . toBe ( true , 'Expected first option to be selected' ) ;
647
+ expect ( overlayContainerElement . querySelectorAll ( 'md-option' ) [ 0 ] . classList )
648
+ . toContain ( 'mat-selected' , 'Expected first option to be selected' ) ;
649
+ } ) ;
650
+
634
651
} ) ;
635
652
636
653
describe ( 'disabled behavior' , ( ) => {
@@ -2516,3 +2533,20 @@ class ResetValuesSelect {
2516
2533
2517
2534
@ViewChild ( MdSelect ) select : MdSelect ;
2518
2535
}
2536
+
2537
+
2538
+ @Component ( {
2539
+ template : `
2540
+ <md-select [formControl]="control">
2541
+ <md-option *ngFor="let food of foods" [value]="food.value">{{ food.viewValue }}</md-option>
2542
+ </md-select>
2543
+ `
2544
+ } )
2545
+ class FalsyValueSelect {
2546
+ foods : any [ ] = [
2547
+ { value : 0 , viewValue : 'Steak' } ,
2548
+ { value : 1 , viewValue : 'Pizza' } ,
2549
+ ] ;
2550
+ control = new FormControl ( ) ;
2551
+ @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
2552
+ }
0 commit comments