@@ -16,7 +16,7 @@ describe('MdSelect', () => {
1616 beforeEach ( async ( ( ) => {
1717 TestBed . configureTestingModule ( {
1818 imports : [ MdSelectModule . forRoot ( ) , ReactiveFormsModule , FormsModule ] ,
19- declarations : [ BasicSelect , NgModelSelect , ManySelects ] ,
19+ declarations : [ BasicSelect , NgModelSelect , ManySelects , NgIfSelect ] ,
2020 providers : [
2121 { provide : OverlayContainer , useFactory : ( ) => {
2222 overlayContainerElement = document . createElement ( 'div' ) ;
@@ -96,14 +96,16 @@ describe('MdSelect', () => {
9696 } ) ;
9797 } ) ) ;
9898
99- it ( 'should set the width of the overlay based on the trigger' , ( ) => {
99+ it ( 'should set the width of the overlay based on the trigger' , async ( ( ) => {
100100 trigger . style . width = '200px' ;
101- trigger . click ( ) ;
102- fixture . detectChanges ( ) ;
103101
104- const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
105- expect ( pane . style . width ) . toBe ( '200px' ) ;
106- } ) ;
102+ fixture . whenStable ( ) . then ( ( ) => {
103+ trigger . click ( ) ;
104+ fixture . detectChanges ( ) ;
105+ const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
106+ expect ( pane . style . minWidth ) . toBe ( '200px' ) ;
107+ } ) ;
108+ } ) ) ;
107109
108110 } ) ;
109111
@@ -997,6 +999,39 @@ describe('MdSelect', () => {
997999
9981000 } ) ;
9991001
1002+ describe ( 'special cases' , ( ) => {
1003+
1004+ it ( 'should handle nesting in an ngIf' , async ( ( ) => {
1005+ const fixture = TestBed . createComponent ( NgIfSelect ) ;
1006+ fixture . detectChanges ( ) ;
1007+
1008+ fixture . componentInstance . isShowing = true ;
1009+ fixture . detectChanges ( ) ;
1010+
1011+ const trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
1012+ trigger . style . width = '300px' ;
1013+
1014+ fixture . whenStable ( ) . then ( ( ) => {
1015+ fixture . detectChanges ( ) ;
1016+ const value = fixture . debugElement . query ( By . css ( '.md-select-value' ) ) ;
1017+ expect ( value . nativeElement . textContent )
1018+ . toContain ( 'Pizza' , `Expected trigger to be populated by the control's initial value.` ) ;
1019+
1020+ trigger . click ( ) ;
1021+ fixture . detectChanges ( ) ;
1022+
1023+ const pane = overlayContainerElement . children [ 0 ] as HTMLElement ;
1024+ expect ( pane . style . minWidth ) . toEqual ( '300px' ) ;
1025+
1026+ expect ( fixture . componentInstance . select . panelOpen ) . toBe ( true ) ;
1027+ expect ( overlayContainerElement . textContent ) . toContain ( 'Steak' ) ;
1028+ expect ( overlayContainerElement . textContent ) . toContain ( 'Pizza' ) ;
1029+ expect ( overlayContainerElement . textContent ) . toContain ( 'Tacos' ) ;
1030+ } ) ;
1031+ } ) ) ;
1032+
1033+ } ) ;
1034+
10001035} ) ;
10011036
10021037@Component ( {
@@ -1062,6 +1097,32 @@ class NgModelSelect {
10621097} )
10631098class ManySelects { }
10641099
1100+ @Component ( {
1101+ selector : 'ng-if-select' ,
1102+ template : `
1103+ <div *ngIf="isShowing">
1104+ <md-select placeholder="Food I want to eat right now" [formControl]="control">
1105+ <md-option *ngFor="let food of foods" [value]="food.value">
1106+ {{ food.viewValue }}
1107+ </md-option>
1108+ </md-select>
1109+ </div>
1110+ `
1111+
1112+ } )
1113+ class NgIfSelect {
1114+ isShowing = false ;
1115+ foods : any [ ] = [
1116+ { value : 'steak-0' , viewValue : 'Steak' } ,
1117+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1118+ { value : 'tacos-2' , viewValue : 'Tacos' }
1119+ ] ;
1120+ control = new FormControl ( 'pizza-1' ) ;
1121+
1122+ @ViewChild ( MdSelect ) select : MdSelect ;
1123+ }
1124+
1125+
10651126
10661127/**
10671128 * TODO: Move this to core testing utility until Angular has event faking
0 commit comments