11import { A , B , DOWN_ARROW , END , HOME , LEFT_ARROW , RIGHT_ARROW , SPACE , UP_ARROW } from '../keycodes' ;
22import { Component , Type , signal , ChangeDetectionStrategy } from '@angular/core' ;
3- import { TestBed , fakeAsync , tick } from '@angular/core/testing' ;
3+ import { TestBed } from '@angular/core/testing' ;
44import { FormControl , ReactiveFormsModule } from '@angular/forms' ;
55import { By } from '@angular/platform-browser' ;
66import { dispatchFakeEvent , dispatchKeyboardEvent , dispatchMouseEvent } from '../testing/private' ;
@@ -23,6 +23,10 @@ function setupComponent<T, O = string>(component: Type<T>) {
2323 } ;
2424}
2525
26+ function wait ( milliseconds : number ) : Promise < void > {
27+ return new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
28+ }
29+
2630describe ( 'CdkOption and CdkListbox' , ( ) => {
2731 describe ( 'id' , ( ) => {
2832 it ( 'should generate unique ids' , ( ) => {
@@ -449,20 +453,18 @@ describe('CdkOption and CdkListbox', () => {
449453 expect ( fixture . componentInstance . changedOption ) . toBe ( null ) ;
450454 } ) ;
451455
452- it ( 'should not handle type ahead on a disabled listbox' , async ( ... args : unknown [ ] ) => {
456+ it ( 'should not handle type ahead on a disabled listbox' , async ( ) => {
453457 const { fixture, testComponent, listboxEl, options} = setupComponent ( ListboxWithOptions ) ;
454- await fakeAsync ( ( ) => {
455- testComponent . isListboxDisabled . set ( true ) ;
456- fixture . detectChanges ( ) ;
458+ testComponent . isListboxDisabled . set ( true ) ;
459+ fixture . detectChanges ( ) ;
457460
458- dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
459- fixture . detectChanges ( ) ;
460- tick ( 200 ) ;
461+ dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
462+ fixture . detectChanges ( ) ;
463+ await wait ( 200 ) ;
461464
462- for ( let option of options ) {
463- expect ( option . isActive ( ) ) . toBeFalse ( ) ;
464- }
465- } ) ( args ) ;
465+ for ( let option of options ) {
466+ expect ( option . isActive ( ) ) . toBeFalse ( ) ;
467+ }
466468 } ) ;
467469
468470 it ( 'should skip disabled options when navigating with arrow keys' , ( ) => {
@@ -561,32 +563,28 @@ describe('CdkOption and CdkListbox', () => {
561563 expect ( optionEls [ 0 ] . classList ) . toContain ( 'cdk-option-active' ) ;
562564 } ) ;
563565
564- it ( 'should change active item using type ahead' , async ( ... args : unknown [ ] ) => {
566+ it ( 'should change active item using type ahead' , async ( ) => {
565567 const { fixture, listbox, listboxEl, options} = setupComponent ( ListboxWithOptions ) ;
566- await fakeAsync ( ( ) => {
567- listbox . focus ( ) ;
568- fixture . detectChanges ( ) ;
568+ listbox . focus ( ) ;
569+ fixture . detectChanges ( ) ;
569570
570- dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
571- fixture . detectChanges ( ) ;
572- tick ( 200 ) ;
571+ dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
572+ fixture . detectChanges ( ) ;
573+ await wait ( 200 ) ;
573574
574- expect ( options [ 2 ] . isActive ( ) ) . toBeTrue ( ) ;
575- } ) ( args ) ;
575+ expect ( options [ 2 ] . isActive ( ) ) . toBeTrue ( ) ;
576576 } ) ;
577577
578- it ( 'should allow custom type ahead label' , async ( ... args : unknown [ ] ) => {
578+ it ( 'should allow custom type ahead label' , async ( ) => {
579579 const { fixture, listbox, listboxEl, options} = setupComponent ( ListboxWithCustomTypeahead ) ;
580- await fakeAsync ( ( ) => {
581- listbox . focus ( ) ;
582- fixture . detectChanges ( ) ;
580+ listbox . focus ( ) ;
581+ fixture . detectChanges ( ) ;
583582
584- dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
585- fixture . detectChanges ( ) ;
586- tick ( 200 ) ;
583+ dispatchKeyboardEvent ( listboxEl , 'keydown' , B ) ;
584+ fixture . detectChanges ( ) ;
585+ await wait ( 200 ) ;
587586
588- expect ( options [ 2 ] . isActive ( ) ) . toBeTrue ( ) ;
589- } ) ( args ) ;
587+ expect ( options [ 2 ] . isActive ( ) ) . toBeTrue ( ) ;
590588 } ) ;
591589
592590 it ( 'should focus and toggle the next item when pressing SHIFT + DOWN_ARROW' , ( ) => {
0 commit comments