@@ -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 )
@@ -412,7 +412,7 @@ describe('MatAutocomplete', () => {
412
412
} ) ) ;
413
413
} ) ;
414
414
415
- it ( 'should have the correct text direction in RTL' , ( ) => {
415
+ it ( 'should have the correct text direction in RTL' , fakeAsync ( ( ) => {
416
416
const rtlFixture = createComponent ( SimpleAutocomplete , [
417
417
{ provide : Directionality , useFactory : ( ) => ( { value : 'rtl' } ) } ,
418
418
] ) ;
@@ -424,18 +424,18 @@ describe('MatAutocomplete', () => {
424
424
const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ! ;
425
425
expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
426
426
427
- } ) ;
427
+ } ) ) ;
428
428
429
429
describe ( 'forms integration' , ( ) => {
430
430
let fixture : ComponentFixture < SimpleAutocomplete > ;
431
431
let input : HTMLInputElement ;
432
432
433
- beforeEach ( ( ) => {
433
+ beforeEach ( fakeAsync ( ( ) => {
434
434
fixture = createComponent ( SimpleAutocomplete ) ;
435
435
fixture . detectChanges ( ) ;
436
436
437
437
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
438
- } ) ;
438
+ } ) ) ;
439
439
440
440
it ( 'should update control value as user types with input value' , ( ) => {
441
441
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -616,22 +616,23 @@ describe('MatAutocomplete', () => {
616
616
. toBe ( true , `Expected control to become touched on blur.` ) ;
617
617
} ) ;
618
618
619
- it ( 'should disable the input when used with a value accessor and without `matInput`' , ( ) => {
620
- overlayContainer . ngOnDestroy ( ) ;
621
- fixture . destroy ( ) ;
622
- TestBed . resetTestingModule ( ) ;
619
+ it ( 'should disable the input when used with a value accessor and without `matInput`' ,
620
+ fakeAsync ( ( ) => {
621
+ overlayContainer . ngOnDestroy ( ) ;
622
+ fixture . destroy ( ) ;
623
+ TestBed . resetTestingModule ( ) ;
623
624
624
- const plainFixture = createComponent ( PlainAutocompleteInputWithFormControl ) ;
625
- plainFixture . detectChanges ( ) ;
626
- input = plainFixture . nativeElement . querySelector ( 'input' ) ;
625
+ const plainFixture = createComponent ( PlainAutocompleteInputWithFormControl ) ;
626
+ plainFixture . detectChanges ( ) ;
627
+ input = plainFixture . nativeElement . querySelector ( 'input' ) ;
627
628
628
- expect ( input . disabled ) . toBe ( false ) ;
629
+ expect ( input . disabled ) . toBe ( false ) ;
629
630
630
- plainFixture . componentInstance . formControl . disable ( ) ;
631
- plainFixture . detectChanges ( ) ;
631
+ plainFixture . componentInstance . formControl . disable ( ) ;
632
+ plainFixture . detectChanges ( ) ;
632
633
633
- expect ( input . disabled ) . toBe ( true ) ;
634
- } ) ;
634
+ expect ( input . disabled ) . toBe ( true ) ;
635
+ } ) ) ;
635
636
636
637
} ) ;
637
638
@@ -1115,12 +1116,12 @@ describe('MatAutocomplete', () => {
1115
1116
let fixture : ComponentFixture < SimpleAutocomplete > ;
1116
1117
let input : HTMLInputElement ;
1117
1118
1118
- beforeEach ( ( ) => {
1119
+ beforeEach ( fakeAsync ( ( ) => {
1119
1120
fixture = createComponent ( SimpleAutocomplete ) ;
1120
1121
fixture . detectChanges ( ) ;
1121
1122
1122
1123
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1123
- } ) ;
1124
+ } ) ) ;
1124
1125
1125
1126
it ( 'should set role of input to combobox' , ( ) => {
1126
1127
expect ( input . getAttribute ( 'role' ) )
@@ -1232,13 +1233,13 @@ describe('MatAutocomplete', () => {
1232
1233
let input : HTMLInputElement ;
1233
1234
let inputReference : HTMLInputElement ;
1234
1235
1235
- beforeEach ( ( ) => {
1236
+ beforeEach ( fakeAsync ( ( ) => {
1236
1237
fixture = createComponent ( SimpleAutocomplete ) ;
1237
1238
fixture . detectChanges ( ) ;
1238
1239
1239
1240
input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1240
1241
inputReference = fixture . debugElement . query ( By . css ( '.mat-input-flex' ) ) . nativeElement ;
1241
- } ) ;
1242
+ } ) ) ;
1242
1243
1243
1244
it ( 'should use below positioning by default' , fakeAsync ( ( ) => {
1244
1245
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -1319,10 +1320,10 @@ describe('MatAutocomplete', () => {
1319
1320
describe ( 'Option selection' , ( ) => {
1320
1321
let fixture : ComponentFixture < SimpleAutocomplete > ;
1321
1322
1322
- beforeEach ( ( ) => {
1323
+ beforeEach ( fakeAsync ( ( ) => {
1323
1324
fixture = createComponent ( SimpleAutocomplete ) ;
1324
1325
fixture . detectChanges ( ) ;
1325
- } ) ;
1326
+ } ) ) ;
1326
1327
1327
1328
it ( 'should deselect any other selected option' , fakeAsync ( ( ) => {
1328
1329
fixture . componentInstance . trigger . openPanel ( ) ;
@@ -1512,10 +1513,10 @@ describe('MatAutocomplete', () => {
1512
1513
describe ( 'without matInput' , ( ) => {
1513
1514
let fixture : ComponentFixture < AutocompleteWithNativeInput > ;
1514
1515
1515
- beforeEach ( ( ) => {
1516
+ beforeEach ( fakeAsync ( ( ) => {
1516
1517
fixture = createComponent ( AutocompleteWithNativeInput ) ;
1517
1518
fixture . detectChanges ( ) ;
1518
- } ) ;
1519
+ } ) ) ;
1519
1520
1520
1521
it ( 'should not throw when clicking outside' , fakeAsync ( ( ) => {
1521
1522
dispatchFakeEvent ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement , 'focus' ) ;
@@ -1528,27 +1529,28 @@ describe('MatAutocomplete', () => {
1528
1529
1529
1530
describe ( 'misc' , ( ) => {
1530
1531
1531
- it ( 'should allow basic use without any forms directives' , ( ) => {
1532
+ it ( 'should allow basic use without any forms directives' , fakeAsync ( ( ) => {
1532
1533
expect ( ( ) => {
1533
1534
const fixture = createComponent ( AutocompleteWithoutForms ) ;
1534
1535
fixture . detectChanges ( ) ;
1535
1536
1536
1537
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1537
1538
typeInElement ( 'd' , input ) ;
1538
1539
fixture . detectChanges ( ) ;
1540
+ tick ( ) ;
1539
1541
1540
1542
const options =
1541
1543
overlayContainerElement . querySelectorAll ( 'mat-option' ) as NodeListOf < HTMLElement > ;
1542
1544
expect ( options . length ) . toBe ( 1 ) ;
1543
1545
} ) . not . toThrowError ( ) ;
1544
- } ) ;
1546
+ } ) ) ;
1545
1547
1546
- it ( 'should display an empty input when the value is undefined with ngModel' , ( ) => {
1548
+ it ( 'should display an empty input when the value is undefined with ngModel' , fakeAsync ( ( ) => {
1547
1549
const fixture = createComponent ( AutocompleteWithNgModel ) ;
1548
1550
fixture . detectChanges ( ) ;
1549
1551
1550
1552
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . value ) . toBe ( '' ) ;
1551
- } ) ;
1553
+ } ) ) ;
1552
1554
1553
1555
it ( 'should display the number when the selected option is the number zero' , fakeAsync ( ( ) => {
1554
1556
const fixture = createComponent ( AutocompleteWithNumbers ) ;
@@ -1560,7 +1562,7 @@ describe('MatAutocomplete', () => {
1560
1562
expect ( fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement . value ) . toBe ( '0' ) ;
1561
1563
} ) ) ;
1562
1564
1563
- it ( 'should work when input is wrapped in ngIf' , ( ) => {
1565
+ it ( 'should work when input is wrapped in ngIf' , fakeAsync ( ( ) => {
1564
1566
const fixture = createComponent ( NgIfAutocomplete ) ;
1565
1567
fixture . detectChanges ( ) ;
1566
1568
@@ -1573,9 +1575,9 @@ describe('MatAutocomplete', () => {
1573
1575
. toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
1574
1576
expect ( overlayContainerElement . textContent )
1575
1577
. toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
1576
- } ) ;
1578
+ } ) ) ;
1577
1579
1578
- it ( 'should filter properly with ngIf after setting the active item' , ( ) => {
1580
+ it ( 'should filter properly with ngIf after setting the active item' , fakeAsync ( ( ) => {
1579
1581
const fixture = createComponent ( NgIfAutocomplete ) ;
1580
1582
fixture . detectChanges ( ) ;
1581
1583
@@ -1589,18 +1591,19 @@ describe('MatAutocomplete', () => {
1589
1591
const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
1590
1592
typeInElement ( 'o' , input ) ;
1591
1593
fixture . detectChanges ( ) ;
1594
+ tick ( ) ;
1592
1595
1593
1596
expect ( fixture . componentInstance . matOptions . length ) . toBe ( 2 ) ;
1594
- } ) ;
1597
+ } ) ) ;
1595
1598
1596
- it ( 'should throw if the user attempts to open the panel too early' , ( ) => {
1599
+ it ( 'should throw if the user attempts to open the panel too early' , fakeAsync ( ( ) => {
1597
1600
const fixture = createComponent ( AutocompleteWithoutPanel ) ;
1598
1601
fixture . detectChanges ( ) ;
1599
1602
1600
1603
expect ( ( ) => {
1601
1604
fixture . componentInstance . trigger . openPanel ( ) ;
1602
1605
} ) . toThrow ( getMatAutocompleteMissingPanelError ( ) ) ;
1603
- } ) ;
1606
+ } ) ) ;
1604
1607
1605
1608
it ( 'should not throw on init, even if the panel is not defined' , fakeAsync ( ( ) => {
1606
1609
expect ( ( ) => {
@@ -1679,7 +1682,7 @@ describe('MatAutocomplete', () => {
1679
1682
1680
1683
} ) ;
1681
1684
1682
- it ( 'should have correct width when opened' , ( ) => {
1685
+ it ( 'should have correct width when opened' , fakeAsync ( ( ) => {
1683
1686
const widthFixture = createComponent ( SimpleAutocomplete ) ;
1684
1687
widthFixture . componentInstance . width = 300 ;
1685
1688
widthFixture . detectChanges ( ) ;
@@ -1702,9 +1705,9 @@ describe('MatAutocomplete', () => {
1702
1705
1703
1706
// Firefox, edge return a decimal value for width, so we need to parse and round it to verify
1704
1707
expect ( Math . ceil ( parseFloat ( overlayPane . style . width as string ) ) ) . toBe ( 500 ) ;
1705
- } ) ;
1708
+ } ) ) ;
1706
1709
1707
- it ( 'should update the width while the panel is open' , ( ) => {
1710
+ it ( 'should update the width while the panel is open' , fakeAsync ( ( ) => {
1708
1711
const widthFixture = createComponent ( SimpleAutocomplete ) ;
1709
1712
1710
1713
widthFixture . componentInstance . width = 300 ;
@@ -1726,7 +1729,7 @@ describe('MatAutocomplete', () => {
1726
1729
widthFixture . detectChanges ( ) ;
1727
1730
1728
1731
expect ( Math . ceil ( parseFloat ( overlayPane . style . width as string ) ) ) . toBe ( 500 ) ;
1729
- } ) ;
1732
+ } ) ) ;
1730
1733
1731
1734
it ( 'should show the panel when the options are initialized later within a component with ' +
1732
1735
'OnPush change detection' , fakeAsync ( ( ) => {
0 commit comments