@@ -102,11 +102,11 @@ describe('MatAutocomplete', () => {
102
102
let fixture : ComponentFixture < SimpleAutocomplete > ;
103
103
let input : HTMLInputElement ;
104
104
105
- beforeEach ( ( ) => {
105
+ beforeEach ( fakeAsync ( ( ) => {
106
106
fixture = createComponent ( SimpleAutocomplete ) ;
107
107
fixture . detectChanges ( ) ;
108
108
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
109
- } ) ;
109
+ } ) ) ;
110
110
111
111
it ( 'should open the panel when the input is focused' , ( ) => {
112
112
expect ( fixture . componentInstance . trigger . panelOpen )
@@ -411,7 +411,7 @@ describe('MatAutocomplete', () => {
411
411
} ) ) ;
412
412
} ) ;
413
413
414
- it ( 'should have the correct text direction in RTL' , ( ) => {
414
+ it ( 'should have the correct text direction in RTL' , fakeAsync ( ( ) => {
415
415
const rtlFixture = createComponent ( SimpleAutocomplete , [
416
416
{ provide : Directionality , useFactory : ( ) => ( { value : 'rtl' } ) } ,
417
417
] ) ;
@@ -423,18 +423,18 @@ describe('MatAutocomplete', () => {
423
423
const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ! ;
424
424
expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
425
425
426
- } ) ;
426
+ } ) ) ;
427
427
428
428
describe ( 'forms integration' , ( ) => {
429
429
let fixture : ComponentFixture < SimpleAutocomplete > ;
430
430
let input : HTMLInputElement ;
431
431
432
- beforeEach ( ( ) => {
432
+ beforeEach ( fakeAsync ( ( ) => {
433
433
fixture = createComponent ( SimpleAutocomplete ) ;
434
434
fixture . detectChanges ( ) ;
435
435
436
436
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
437
- } ) ;
437
+ } ) ) ;
438
438
439
439
it ( 'should update control value as user types with input value' , ( ) => {
440
440
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -615,22 +615,23 @@ describe('MatAutocomplete', () => {
615
615
. toBe ( true , `Expected control to become touched on blur.` ) ;
616
616
} ) ;
617
617
618
- it ( 'should disable the input when used with a value accessor and without `matInput`' , ( ) => {
619
- overlayContainer . ngOnDestroy ( ) ;
620
- fixture . destroy ( ) ;
621
- TestBed . resetTestingModule ( ) ;
618
+ it ( 'should disable the input when used with a value accessor and without `matInput`' ,
619
+ fakeAsync ( ( ) => {
620
+ overlayContainer . ngOnDestroy ( ) ;
621
+ fixture . destroy ( ) ;
622
+ TestBed . resetTestingModule ( ) ;
622
623
623
- const plainFixture = createComponent ( PlainAutocompleteInputWithFormControl ) ;
624
- plainFixture . detectChanges ( ) ;
625
- input = plainFixture . nativeElement . querySelector ( 'input' ) ;
624
+ const plainFixture = createComponent ( PlainAutocompleteInputWithFormControl ) ;
625
+ plainFixture . detectChanges ( ) ;
626
+ input = plainFixture . nativeElement . querySelector ( 'input' ) ;
626
627
627
- expect ( input . disabled ) . toBe ( false ) ;
628
+ expect ( input . disabled ) . toBe ( false ) ;
628
629
629
- plainFixture . componentInstance . formControl . disable ( ) ;
630
- plainFixture . detectChanges ( ) ;
630
+ plainFixture . componentInstance . formControl . disable ( ) ;
631
+ plainFixture . detectChanges ( ) ;
631
632
632
- expect ( input . disabled ) . toBe ( true ) ;
633
- } ) ;
633
+ expect ( input . disabled ) . toBe ( true ) ;
634
+ } ) ) ;
634
635
635
636
} ) ;
636
637
@@ -1088,12 +1089,12 @@ describe('MatAutocomplete', () => {
1088
1089
let fixture : ComponentFixture < SimpleAutocomplete > ;
1089
1090
let input : HTMLInputElement ;
1090
1091
1091
- beforeEach ( ( ) => {
1092
+ beforeEach ( fakeAsync ( ( ) => {
1092
1093
fixture = createComponent ( SimpleAutocomplete ) ;
1093
1094
fixture . detectChanges ( ) ;
1094
1095
1095
1096
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1096
- } ) ;
1097
+ } ) ) ;
1097
1098
1098
1099
it ( 'should set role of input to combobox' , ( ) => {
1099
1100
expect ( input . getAttribute ( 'role' ) )
@@ -1205,13 +1206,13 @@ describe('MatAutocomplete', () => {
1205
1206
let input : HTMLInputElement ;
1206
1207
let inputReference : HTMLInputElement ;
1207
1208
1208
- beforeEach ( ( ) => {
1209
+ beforeEach ( fakeAsync ( ( ) => {
1209
1210
fixture = createComponent ( SimpleAutocomplete ) ;
1210
1211
fixture . detectChanges ( ) ;
1211
1212
1212
1213
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1213
1214
inputReference = fixture . debugElement . query ( By . css ( '.mat-input-flex' ) ) . nativeElement ;
1214
- } ) ;
1215
+ } ) ) ;
1215
1216
1216
1217
it ( 'should use below positioning by default' , fakeAsync ( ( ) => {
1217
1218
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -1292,10 +1293,10 @@ describe('MatAutocomplete', () => {
1292
1293
describe ( 'Option selection' , ( ) => {
1293
1294
let fixture : ComponentFixture < SimpleAutocomplete > ;
1294
1295
1295
- beforeEach ( ( ) => {
1296
+ beforeEach ( fakeAsync ( ( ) => {
1296
1297
fixture = createComponent ( SimpleAutocomplete ) ;
1297
1298
fixture . detectChanges ( ) ;
1298
- } ) ;
1299
+ } ) ) ;
1299
1300
1300
1301
it ( 'should deselect any other selected option' , fakeAsync ( ( ) => {
1301
1302
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -1485,10 +1486,10 @@ describe('MatAutocomplete', () => {
1485
1486
describe ( 'without matInput' , ( ) => {
1486
1487
let fixture : ComponentFixture < AutocompleteWithNativeInput > ;
1487
1488
1488
- beforeEach ( ( ) => {
1489
+ beforeEach ( fakeAsync ( ( ) => {
1489
1490
fixture = createComponent ( AutocompleteWithNativeInput ) ;
1490
1491
fixture . detectChanges ( ) ;
1491
- } ) ;
1492
+ } ) ) ;
1492
1493
1493
1494
it ( 'should not throw when clicking outside' , fakeAsync ( ( ) => {
1494
1495
dispatchFakeEvent ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement , 'focus' ) ;
@@ -1501,27 +1502,28 @@ describe('MatAutocomplete', () => {
1501
1502
1502
1503
describe ( 'misc' , ( ) => {
1503
1504
1504
- it ( 'should allow basic use without any forms directives' , ( ) => {
1505
+ it ( 'should allow basic use without any forms directives' , fakeAsync ( ( ) => {
1505
1506
expect ( ( ) => {
1506
1507
const fixture = createComponent ( AutocompleteWithoutForms ) ;
1507
1508
fixture . detectChanges ( ) ;
1508
1509
1509
1510
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1510
1511
typeInElement ( 'd' , input ) ;
1511
1512
fixture . detectChanges ( ) ;
1513
+ tick ( ) ;
1512
1514
1513
1515
const options =
1514
1516
overlayContainerElement . querySelectorAll ( 'mat-option' ) as NodeListOf < HTMLElement > ;
1515
1517
expect ( options . length ) . toBe ( 1 ) ;
1516
1518
} ) . not . toThrowError ( ) ;
1517
- } ) ;
1519
+ } ) ) ;
1518
1520
1519
- it ( 'should display an empty input when the value is undefined with ngModel' , ( ) => {
1521
+ it ( 'should display an empty input when the value is undefined with ngModel' , fakeAsync ( ( ) => {
1520
1522
const fixture = createComponent ( AutocompleteWithNgModel ) ;
1521
1523
fixture . detectChanges ( ) ;
1522
1524
1523
1525
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . value ) . toBe ( '' ) ;
1524
- } ) ;
1526
+ } ) ) ;
1525
1527
1526
1528
it ( 'should display the number when the selected option is the number zero' , fakeAsync ( ( ) => {
1527
1529
const fixture = createComponent ( AutocompleteWithNumbers ) ;
@@ -1533,7 +1535,7 @@ describe('MatAutocomplete', () => {
1533
1535
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . value ) . toBe ( '0' ) ;
1534
1536
} ) ) ;
1535
1537
1536
- it ( 'should work when input is wrapped in ngIf' , ( ) => {
1538
+ it ( 'should work when input is wrapped in ngIf' , fakeAsync ( ( ) => {
1537
1539
const fixture = createComponent ( NgIfAutocomplete ) ;
1538
1540
fixture . detectChanges ( ) ;
1539
1541
@@ -1546,9 +1548,9 @@ describe('MatAutocomplete', () => {
1546
1548
. toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
1547
1549
expect ( overlayContainerElement . textContent )
1548
1550
. toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
1549
- } ) ;
1551
+ } ) ) ;
1550
1552
1551
- it ( 'should filter properly with ngIf after setting the active item' , ( ) => {
1553
+ it ( 'should filter properly with ngIf after setting the active item' , fakeAsync ( ( ) => {
1552
1554
const fixture = createComponent ( NgIfAutocomplete ) ;
1553
1555
fixture . detectChanges ( ) ;
1554
1556
@@ -1562,18 +1564,19 @@ describe('MatAutocomplete', () => {
1562
1564
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1563
1565
typeInElement ( 'o' , input ) ;
1564
1566
fixture . detectChanges ( ) ;
1567
+ tick ( ) ;
1565
1568
1566
1569
expect ( fixture . componentInstance . matOptions . length ) . toBe ( 2 ) ;
1567
- } ) ;
1570
+ } ) ) ;
1568
1571
1569
- it ( 'should throw if the user attempts to open the panel too early' , ( ) => {
1572
+ it ( 'should throw if the user attempts to open the panel too early' , fakeAsync ( ( ) => {
1570
1573
const fixture = createComponent ( AutocompleteWithoutPanel ) ;
1571
1574
fixture . detectChanges ( ) ;
1572
1575
1573
1576
expect ( ( ) => {
1574
1577
fixture . componentInstance . trigger . openPanel ( ) ;
1575
1578
} ) . toThrow ( getMatAutocompleteMissingPanelError ( ) ) ;
1576
- } ) ;
1579
+ } ) ) ;
1577
1580
1578
1581
it ( 'should not throw on init, even if the panel is not defined' , fakeAsync ( ( ) => {
1579
1582
expect ( ( ) => {
@@ -1652,7 +1655,7 @@ describe('MatAutocomplete', () => {
1652
1655
1653
1656
} ) ;
1654
1657
1655
- it ( 'should have correct width when opened' , ( ) => {
1658
+ it ( 'should have correct width when opened' , fakeAsync ( ( ) => {
1656
1659
const widthFixture = createComponent ( SimpleAutocomplete ) ;
1657
1660
widthFixture . componentInstance . width = 300 ;
1658
1661
widthFixture . detectChanges ( ) ;
@@ -1675,9 +1678,9 @@ describe('MatAutocomplete', () => {
1675
1678
1676
1679
// Firefox, edge return a decimal value for width, so we need to parse and round it to verify
1677
1680
expect ( Math . ceil ( parseFloat ( overlayPane . style . width as string ) ) ) . toBe ( 500 ) ;
1678
- } ) ;
1681
+ } ) ) ;
1679
1682
1680
- it ( 'should update the width while the panel is open' , ( ) => {
1683
+ it ( 'should update the width while the panel is open' , fakeAsync ( ( ) => {
1681
1684
const widthFixture = createComponent ( SimpleAutocomplete ) ;
1682
1685
1683
1686
widthFixture . componentInstance . width = 300 ;
@@ -1699,7 +1702,7 @@ describe('MatAutocomplete', () => {
1699
1702
widthFixture . detectChanges ( ) ;
1700
1703
1701
1704
expect ( Math . ceil ( parseFloat ( overlayPane . style . width as string ) ) ) . toBe ( 500 ) ;
1702
- } ) ;
1705
+ } ) ) ;
1703
1706
1704
1707
it ( 'should show the panel when the options are initialized later within a component with ' +
1705
1708
'OnPush change detection' , fakeAsync ( ( ) => {
0 commit comments