@@ -1162,20 +1162,22 @@ describe('MatSelect', () => {
1162
1162
fixture . componentInstance . control . setValue ( 'chips-4' ) ;
1163
1163
fixture . detectChanges ( ) ;
1164
1164
1165
- trigger . click ( ) ;
1166
- fixture . detectChanges ( ) ;
1165
+ fixture . whenStable ( ) . then ( ( ) => {
1166
+ trigger . click ( ) ;
1167
+ fixture . detectChanges ( ) ;
1167
1168
1168
- const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1169
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1169
1170
1170
- fixture . whenStable ( ) . then ( ( ) => {
1171
- // The selected option should be scrolled to the center of the panel.
1172
- // This will be its original offset from the scrollTop - half the panel height + half the
1173
- // option height. 4 (index) * 48 (option height) = 192px offset from scrollTop
1174
- // 192 - 256/2 + 48/2 = 88px
1175
- expect ( scrollContainer . scrollTop )
1176
- . toEqual ( 88 , `Expected overlay panel to be scrolled to center the selected option.` ) ;
1171
+ fixture . whenStable ( ) . then ( ( ) => {
1172
+ // The selected option should be scrolled to the center of the panel.
1173
+ // This will be its original offset from the scrollTop - half the panel height + half
1174
+ // the option height. 4 (index) * 48 (option height) = 192px offset from scrollTop
1175
+ // 192 - 256/2 + 48/2 = 88px
1176
+ expect ( scrollContainer . scrollTop )
1177
+ . toEqual ( 88 , `Expected overlay panel to be scrolled to center the selected option.` ) ;
1177
1178
1178
- checkTriggerAlignedWithOption ( 4 ) ;
1179
+ checkTriggerAlignedWithOption ( 4 ) ;
1180
+ } ) ;
1179
1181
} ) ;
1180
1182
} ) ) ;
1181
1183
@@ -1184,19 +1186,21 @@ describe('MatSelect', () => {
1184
1186
fixture . componentInstance . control . setValue ( 'sushi-7' ) ;
1185
1187
fixture . detectChanges ( ) ;
1186
1188
1187
- trigger . click ( ) ;
1188
- fixture . detectChanges ( ) ;
1189
+ fixture . whenStable ( ) . then ( ( ) => {
1190
+ trigger . click ( ) ;
1191
+ fixture . detectChanges ( ) ;
1189
1192
1190
- const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1193
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1191
1194
1192
- fixture . whenStable ( ) . then ( ( ) => {
1193
- // The selected option should be scrolled to the max scroll position.
1194
- // This will be the height of the scrollContainer - the panel height.
1195
- // 8 options * 48px = 384 scrollContainer height, 384 - 256 = 128px max scroll
1196
- expect ( scrollContainer . scrollTop )
1197
- . toEqual ( 128 , `Expected overlay panel to be scrolled to its maximum position.` ) ;
1195
+ fixture . whenStable ( ) . then ( ( ) => {
1196
+ // The selected option should be scrolled to the max scroll position.
1197
+ // This will be the height of the scrollContainer - the panel height.
1198
+ // 8 options * 48px = 384 scrollContainer height, 384 - 256 = 128px max scroll
1199
+ expect ( scrollContainer . scrollTop )
1200
+ . toEqual ( 128 , `Expected overlay panel to be scrolled to its maximum position.` ) ;
1198
1201
1199
- checkTriggerAlignedWithOption ( 7 ) ;
1202
+ checkTriggerAlignedWithOption ( 7 ) ;
1203
+ } ) ;
1200
1204
} ) ;
1201
1205
} ) ) ;
1202
1206
@@ -1279,17 +1283,19 @@ describe('MatSelect', () => {
1279
1283
fixture . componentInstance . control . setValue ( 'chips-4' ) ;
1280
1284
fixture . detectChanges ( ) ;
1281
1285
1282
- trigger . click ( ) ;
1283
- fixture . detectChanges ( ) ;
1286
+ fixture . whenStable ( ) . then ( ( ) => {
1287
+ trigger . click ( ) ;
1288
+ fixture . detectChanges ( ) ;
1284
1289
1285
- const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1290
+ const scrollContainer = document . querySelector ( '.cdk-overlay-pane .mat-select-panel' ) ! ;
1286
1291
1287
- fixture . whenStable ( ) . then ( ( ) => {
1288
- expect ( Math . ceil ( scrollContainer . scrollTop ) )
1289
- . toEqual ( Math . ceil ( idealScrollTop + 5 ) ,
1290
- `Expected panel to adjust scroll position to fit in viewport.` ) ;
1292
+ fixture . whenStable ( ) . then ( ( ) => {
1293
+ expect ( Math . ceil ( scrollContainer . scrollTop ) )
1294
+ . toEqual ( Math . ceil ( idealScrollTop + 5 ) ,
1295
+ `Expected panel to adjust scroll position to fit in viewport.` ) ;
1291
1296
1292
- checkTriggerAlignedWithOption ( 4 ) ;
1297
+ checkTriggerAlignedWithOption ( 4 ) ;
1298
+ } ) ;
1293
1299
} ) ;
1294
1300
} ) ) ;
1295
1301
@@ -1402,23 +1408,25 @@ describe('MatSelect', () => {
1402
1408
fixture . componentInstance . control . setValue ( 'sushi-7' ) ;
1403
1409
fixture . detectChanges ( ) ;
1404
1410
1405
- trigger . click ( ) ;
1406
- fixture . detectChanges ( ) ;
1407
-
1408
1411
fixture . whenStable ( ) . then ( ( ) => {
1409
- const overlayPane = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1410
- const triggerTop = trigger . getBoundingClientRect ( ) . top ;
1411
- const overlayTop = overlayPane . getBoundingClientRect ( ) . top ;
1412
- const scrollContainer = overlayPane . querySelector ( '.mat-select-panel' ) ! ;
1412
+ trigger . click ( ) ;
1413
+ fixture . detectChanges ( ) ;
1414
+
1415
+ fixture . whenStable ( ) . then ( ( ) => {
1416
+ const overlayPane = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1417
+ const triggerTop = trigger . getBoundingClientRect ( ) . top ;
1418
+ const overlayTop = overlayPane . getBoundingClientRect ( ) . top ;
1419
+ const scrollContainer = overlayPane . querySelector ( '.mat-select-panel' ) ! ;
1413
1420
1414
- // Expect scroll to remain at the max scroll position
1415
- expect ( scrollContainer . scrollTop ) . toEqual ( 128 , `Expected panel to be at max scroll.` ) ;
1421
+ // Expect scroll to remain at the max scroll position
1422
+ expect ( scrollContainer . scrollTop ) . toEqual ( 128 , `Expected panel to be at max scroll.` ) ;
1416
1423
1417
- expect ( Math . floor ( overlayTop ) )
1418
- . toEqual ( Math . floor ( triggerTop ) , `Expected trigger top to align with overlay top.` ) ;
1424
+ expect ( Math . floor ( overlayTop ) )
1425
+ . toEqual ( Math . floor ( triggerTop ) , `Expected trigger top to align with overlay top.` ) ;
1419
1426
1420
- expect ( fixture . componentInstance . select . _transformOrigin )
1421
- . toContain ( `top` , `Expected panel animation to originate at the top.` ) ;
1427
+ expect ( fixture . componentInstance . select . _transformOrigin )
1428
+ . toContain ( `top` , `Expected panel animation to originate at the top.` ) ;
1429
+ } ) ;
1422
1430
} ) ;
1423
1431
} ) ) ;
1424
1432
@@ -1574,23 +1582,25 @@ describe('MatSelect', () => {
1574
1582
fixture . componentInstance . control . setValue ( 'chips-4' ) ;
1575
1583
fixture . detectChanges ( ) ;
1576
1584
1577
- // Scroll the select into view
1578
- setScrollTop ( 1700 ) ;
1579
-
1580
- // In the iOS simulator (BrowserStack & SauceLabs), adding the content to the
1581
- // body causes karma's iframe for the test to stretch to fit that content once we attempt to
1582
- // scroll the page. Setting width / height / maxWidth / maxHeight on the iframe does not
1583
- // successfully constrain its size. As such, skip assertions in environments where the
1584
- // window size has changed since the start of the test.
1585
- if ( window . innerHeight > startingWindowHeight ) {
1586
- return ;
1587
- }
1585
+ fixture . whenStable ( ) . then ( ( ) => {
1586
+ // Scroll the select into view
1587
+ setScrollTop ( 1700 ) ;
1588
+
1589
+ // In the iOS simulator (BrowserStack & SauceLabs), adding the content to the
1590
+ // body causes karma's iframe for the test to stretch to fit that content once we attempt
1591
+ // to scroll the page. Setting width / height / maxWidth / maxHeight on the iframe does
1592
+ // not successfully constrain its size. As such, skip assertions in environments where the
1593
+ // window size has changed since the start of the test.
1594
+ if ( window . innerHeight > startingWindowHeight ) {
1595
+ return ;
1596
+ }
1588
1597
1589
- trigger . click ( ) ;
1590
- fixture . detectChanges ( ) ;
1598
+ trigger . click ( ) ;
1599
+ fixture . detectChanges ( ) ;
1591
1600
1592
- fixture . whenStable ( ) . then ( ( ) => {
1593
- checkTriggerAlignedWithOption ( 4 ) ;
1601
+ fixture . whenStable ( ) . then ( ( ) => {
1602
+ checkTriggerAlignedWithOption ( 4 ) ;
1603
+ } ) ;
1594
1604
} ) ;
1595
1605
} ) ) ;
1596
1606
@@ -1601,15 +1611,17 @@ describe('MatSelect', () => {
1601
1611
fixture . componentInstance . control . setValue ( 'chips-4' ) ;
1602
1612
fixture . detectChanges ( ) ;
1603
1613
1604
- trigger . click ( ) ;
1605
- fixture . detectChanges ( ) ;
1606
-
1607
1614
fixture . whenStable ( ) . then ( ( ) => {
1608
- setScrollTop ( 100 ) ;
1609
- scrolledSubject . next ( ) ;
1615
+ trigger . click ( ) ;
1610
1616
fixture . detectChanges ( ) ;
1611
1617
1612
- checkTriggerAlignedWithOption ( 4 ) ;
1618
+ fixture . whenStable ( ) . then ( ( ) => {
1619
+ setScrollTop ( 100 ) ;
1620
+ scrolledSubject . next ( ) ;
1621
+ fixture . detectChanges ( ) ;
1622
+
1623
+ checkTriggerAlignedWithOption ( 4 ) ;
1624
+ } ) ;
1613
1625
} ) ;
1614
1626
} ) ) ;
1615
1627
0 commit comments