11import { LEFT_ARROW } from '@angular/cdk/keycodes' ;
22import { dispatchFakeEvent , dispatchKeyboardEvent } from '@angular/cdk/testing/private' ;
33import { Component , OnInit , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
4- import { waitForAsync , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
4+ import {
5+ waitForAsync ,
6+ ComponentFixture ,
7+ fakeAsync ,
8+ TestBed ,
9+ tick ,
10+ flush ,
11+ } from '@angular/core/testing' ;
512import { By } from '@angular/platform-browser' ;
613import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
714import { CommonModule } from '@angular/common' ;
@@ -299,7 +306,7 @@ describe('MatTabGroup', () => {
299306 . toBe ( true ) ;
300307 } ) ;
301308
302- it ( 'should emit focusChange when a tab receives focus' , ( ) => {
309+ it ( 'should emit focusChange when a tab receives focus' , fakeAsync ( ( ) => {
303310 spyOn ( fixture . componentInstance , 'handleFocus' ) ;
304311 fixture . detectChanges ( ) ;
305312
@@ -309,13 +316,15 @@ describe('MatTabGroup', () => {
309316
310317 // In order to verify that the `focusChange` event also fires with the correct
311318 // index, we focus the second tab before testing the keyboard navigation.
312- dispatchFakeEvent ( tabLabels [ 1 ] . nativeElement , 'focus' ) ;
319+ dispatchFakeEvent ( tabLabels [ 2 ] . nativeElement , 'focus' ) ;
320+ fixture . detectChanges ( ) ;
321+ flush ( ) ;
313322 fixture . detectChanges ( ) ;
314323
315324 expect ( fixture . componentInstance . handleFocus ) . toHaveBeenCalledTimes ( 1 ) ;
316325 expect ( fixture . componentInstance . handleFocus )
317- . toHaveBeenCalledWith ( jasmine . objectContaining ( { index : 1 } ) ) ;
318- } ) ;
326+ . toHaveBeenCalledWith ( jasmine . objectContaining ( { index : 2 } ) ) ;
327+ } ) ) ;
319328
320329 } ) ;
321330
0 commit comments