1+ import { Directionality } from '@angular/cdk/bidi' ;
2+ import { A , ESCAPE } from '@angular/cdk/keycodes' ;
3+ import { Overlay , OverlayContainer , ScrollDispatcher } from '@angular/cdk/overlay' ;
4+ import { _supportsShadowDom } from '@angular/cdk/platform' ;
15import {
2- ComponentFixture ,
3- fakeAsync ,
4- flushMicrotasks ,
5- TestBed ,
6- tick ,
7- flush ,
8- } from '@angular/core/testing' ;
6+ createKeyboardEvent ,
7+ dispatchEvent ,
8+ dispatchKeyboardEvent ,
9+ } from '@angular/cdk/testing/private' ;
10+ import { Location } from '@angular/common' ;
11+ import { SpyLocation } from '@angular/common/testing' ;
912import {
1013 ChangeDetectionStrategy ,
1114 Component ,
1215 ComponentRef ,
1316 Directive ,
14- inject ,
1517 Inject ,
1618 InjectionToken ,
1719 Injector ,
1820 TemplateRef ,
1921 ViewChild ,
2022 ViewContainerRef ,
2123 ViewEncapsulation ,
24+ inject ,
2225} from '@angular/core' ;
23- import { By } from '@angular/platform-browser' ;
24- import { Location } from '@angular/common' ;
25- import { SpyLocation } from '@angular/common/testing' ;
26- import { Directionality } from '@angular/cdk/bidi' ;
27- import { Overlay , OverlayContainer , ScrollDispatcher } from '@angular/cdk/overlay' ;
28- import { A , ESCAPE } from '@angular/cdk/keycodes' ;
29- import { _supportsShadowDom } from '@angular/cdk/platform' ;
3026import {
31- dispatchKeyboardEvent ,
32- createKeyboardEvent ,
33- dispatchEvent ,
34- } from '@angular/cdk/testing/private' ;
27+ ComponentFixture ,
28+ TestBed ,
29+ fakeAsync ,
30+ flush ,
31+ flushMicrotasks ,
32+ tick ,
33+ } from '@angular/core/testing' ;
34+ import { By } from '@angular/platform-browser' ;
3535import { Subject } from 'rxjs' ;
3636import { DIALOG_DATA , Dialog , DialogModule , DialogRef } from './index' ;
3737
@@ -282,17 +282,20 @@ describe('Dialog', () => {
282282 const spy = jasmine . createSpy ( 'backdropClick spy' ) ;
283283 dialogRef . backdropClick . subscribe ( spy ) ;
284284 viewContainerFixture . detectChanges ( ) ;
285+ flush ( ) ;
285286
286287 const backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
287288
288289 backdrop . click ( ) ;
289290 viewContainerFixture . detectChanges ( ) ;
291+ flush ( ) ;
290292 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
291293
292294 // Additional clicks after the dialog has closed should not be emitted
293295 dialogRef . disableClose = false ;
294296 backdrop . click ( ) ;
295297 viewContainerFixture . detectChanges ( ) ;
298+ flush ( ) ;
296299 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
297300 } ) ) ;
298301
@@ -303,6 +306,7 @@ describe('Dialog', () => {
303306 dialogRef . keydownEvents . subscribe ( spy ) ;
304307
305308 viewContainerFixture . detectChanges ( ) ;
309+ flush ( ) ;
306310
307311 let backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
308312 let container = overlayContainerElement . querySelector ( 'cdk-dialog-container' ) as HTMLElement ;
@@ -757,9 +761,11 @@ describe('Dialog', () => {
757761 fakeAsync ( ( ) => {
758762 const templateInjectFixture = TestBed . createComponent ( TemplateInjectorParentComponent ) ;
759763 templateInjectFixture . detectChanges ( ) ;
764+ flush ( ) ;
760765
761766 dialog . open ( templateInjectFixture . componentInstance . templateRef ) ;
762767 templateInjectFixture . detectChanges ( ) ;
768+ flush ( ) ;
763769
764770 expect ( templateInjectFixture . componentInstance . innerComponentValue ) . toBe (
765771 'hello from parent component' ,
@@ -840,7 +846,7 @@ describe('Dialog', () => {
840846 } ) ;
841847
842848 viewContainerFixture . detectChanges ( ) ;
843- flushMicrotasks ( ) ;
849+ flush ( ) ;
844850
845851 expect ( document . activeElement ! . tagName )
846852 . withContext ( 'Expected first tabbable element (input) in the dialog to be focused.' )
@@ -910,17 +916,15 @@ describe('Dialog', () => {
910916
911917 let dialogRef = dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
912918
913- flushMicrotasks ( ) ;
914919 viewContainerFixture . detectChanges ( ) ;
915- flushMicrotasks ( ) ;
920+ flush ( ) ;
916921
917922 expect ( document . activeElement ! . id ) . not . toBe (
918923 'dialog-trigger' ,
919924 'Expected the focus to change when dialog was opened.' ,
920925 ) ;
921926
922927 dialogRef . close ( ) ;
923- flushMicrotasks ( ) ;
924928 viewContainerFixture . detectChanges ( ) ;
925929 flush ( ) ;
926930
@@ -939,18 +943,18 @@ describe('Dialog', () => {
939943 viewContainerFixture . destroy ( ) ;
940944 const fixture = TestBed . createComponent ( ShadowDomComponent ) ;
941945 fixture . detectChanges ( ) ;
946+ flush ( ) ;
942947 const button = fixture . debugElement . query ( By . css ( 'button' ) ) ! . nativeElement ;
943948
944949 button . focus ( ) ;
945950
946951 const dialogRef = dialog . open ( PizzaMsg ) ;
947- flushMicrotasks ( ) ;
948952 fixture . detectChanges ( ) ;
949- flushMicrotasks ( ) ;
953+ flush ( ) ;
950954
951955 const spy = spyOn ( button , 'focus' ) . and . callThrough ( ) ;
952956 dialogRef . close ( ) ;
953- flushMicrotasks ( ) ;
957+ flush ( ) ;
954958 fixture . detectChanges ( ) ;
955959 tick ( 500 ) ;
956960
@@ -994,7 +998,7 @@ describe('Dialog', () => {
994998 dialog . open ( DialogWithoutFocusableElements ) ;
995999
9961000 viewContainerFixture . detectChanges ( ) ;
997- flushMicrotasks ( ) ;
1001+ flush ( ) ;
9981002
9991003 expect ( document . activeElement ! . tagName . toLowerCase ( ) )
10001004 . withContext ( 'Expected dialog container to be focused.' )
@@ -1013,14 +1017,12 @@ describe('Dialog', () => {
10131017 restoreFocus : false ,
10141018 } ) ;
10151019
1016- flushMicrotasks ( ) ;
10171020 viewContainerFixture . detectChanges ( ) ;
1018- flushMicrotasks ( ) ;
1021+ flush ( ) ;
10191022
10201023 expect ( document . activeElement ! . id ) . not . toBe ( 'dialog-trigger' ) ;
10211024
10221025 dialogRef . close ( ) ;
1023- flushMicrotasks ( ) ;
10241026 viewContainerFixture . detectChanges ( ) ;
10251027 flush ( ) ;
10261028
0 commit comments