@@ -39,7 +39,8 @@ describe('MdSelect', () => {
3939 FloatPlaceholderSelect ,
4040 SelectWithErrorSibling ,
4141 ThrowsErrorOnInit ,
42- BasicSelectOnPush
42+ BasicSelectOnPush ,
43+ BasicSelectOnPushPreselected
4344 ] ,
4445 providers : [
4546 { provide : OverlayContainer , useFactory : ( ) => {
@@ -1322,16 +1323,25 @@ describe('MdSelect', () => {
13221323 } ) ;
13231324
13241325 describe ( 'with OnPush change detection' , ( ) => {
1325- let fixture : ComponentFixture < BasicSelectOnPush > ;
1326- let trigger : HTMLElement ;
1326+ it ( 'should set the trigger text based on the value when initialized' , async ( ( ) => {
1327+ let fixture = TestBed . createComponent ( BasicSelectOnPushPreselected ) ;
13271328
1328- beforeEach ( ( ) => {
1329- fixture = TestBed . createComponent ( BasicSelectOnPush ) ;
13301329 fixture . detectChanges ( ) ;
1331- trigger = fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
1332- } ) ;
1330+
1331+ fixture . whenStable ( ) . then ( ( ) => {
1332+ let trigger = fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
1333+
1334+ fixture . detectChanges ( ) ;
1335+
1336+ expect ( trigger . textContent ) . toContain ( 'Pizza' ) ;
1337+ } ) ;
1338+ } ) ) ;
13331339
13341340 it ( 'should update the trigger based on the value' , ( ) => {
1341+ let fixture = TestBed . createComponent ( BasicSelectOnPush ) ;
1342+ fixture . detectChanges ( ) ;
1343+ let trigger = fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
1344+
13351345 fixture . componentInstance . control . setValue ( 'pizza-1' ) ;
13361346 fixture . detectChanges ( ) ;
13371347
@@ -1342,7 +1352,9 @@ describe('MdSelect', () => {
13421352
13431353 expect ( trigger . textContent ) . not . toContain ( 'Pizza' ) ;
13441354 } ) ;
1355+
13451356 } ) ;
1357+
13461358} ) ;
13471359
13481360
@@ -1561,9 +1573,26 @@ class BasicSelectOnPush {
15611573 { value : 'tacos-2' , viewValue : 'Tacos' } ,
15621574 ] ;
15631575 control = new FormControl ( ) ;
1576+ }
15641577
1565- @ViewChild ( MdSelect ) select : MdSelect ;
1566- @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
1578+ @Component ( {
1579+ selector : 'basic-select-on-push-preselected' ,
1580+ changeDetection : ChangeDetectionStrategy . OnPush ,
1581+ template : `
1582+ <md-select placeholder="Food" [formControl]="control">
1583+ <md-option *ngFor="let food of foods" [value]="food.value">
1584+ {{ food.viewValue }}
1585+ </md-option>
1586+ </md-select>
1587+ `
1588+ } )
1589+ class BasicSelectOnPushPreselected {
1590+ foods : any [ ] = [
1591+ { value : 'steak-0' , viewValue : 'Steak' } ,
1592+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1593+ { value : 'tacos-2' , viewValue : 'Tacos' } ,
1594+ ] ;
1595+ control = new FormControl ( 'pizza-1' ) ;
15671596}
15681597
15691598@Component ( {
0 commit comments