@@ -39,7 +39,8 @@ describe('MdSelect', () => {
39
39
FloatPlaceholderSelect ,
40
40
SelectWithErrorSibling ,
41
41
ThrowsErrorOnInit ,
42
- BasicSelectOnPush
42
+ BasicSelectOnPush ,
43
+ BasicSelectOnPushPreselected
43
44
] ,
44
45
providers : [
45
46
{ provide : OverlayContainer , useFactory : ( ) => {
@@ -1322,16 +1323,25 @@ describe('MdSelect', () => {
1322
1323
} ) ;
1323
1324
1324
1325
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 ) ;
1327
1328
1328
- beforeEach ( ( ) => {
1329
- fixture = TestBed . createComponent ( BasicSelectOnPush ) ;
1330
1329
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
+ } ) ) ;
1333
1339
1334
1340
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
+
1335
1345
fixture . componentInstance . control . setValue ( 'pizza-1' ) ;
1336
1346
fixture . detectChanges ( ) ;
1337
1347
@@ -1342,7 +1352,9 @@ describe('MdSelect', () => {
1342
1352
1343
1353
expect ( trigger . textContent ) . not . toContain ( 'Pizza' ) ;
1344
1354
} ) ;
1355
+
1345
1356
} ) ;
1357
+
1346
1358
} ) ;
1347
1359
1348
1360
@@ -1561,9 +1573,26 @@ class BasicSelectOnPush {
1561
1573
{ value : 'tacos-2' , viewValue : 'Tacos' } ,
1562
1574
] ;
1563
1575
control = new FormControl ( ) ;
1576
+ }
1564
1577
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' ) ;
1567
1596
}
1568
1597
1569
1598
@Component ( {
0 commit comments