1
- import {
2
- waitForAsync ,
3
- fakeAsync ,
4
- tick ,
5
- ComponentFixture ,
6
- TestBed ,
7
- flush ,
8
- } from '@angular/core/testing' ;
1
+ import { Direction , Directionality } from '@angular/cdk/bidi' ;
2
+ import { CdkPortal , ComponentPortal , TemplatePortal } from '@angular/cdk/portal' ;
3
+ import { Location } from '@angular/common' ;
4
+ import { SpyLocation } from '@angular/common/testing' ;
9
5
import {
10
6
Component ,
11
- ViewChild ,
12
- ViewContainerRef ,
13
7
ErrorHandler ,
14
- Injectable ,
15
8
EventEmitter ,
16
- NgZone ,
9
+ Injectable ,
17
10
Type ,
18
- provideZoneChangeDetection ,
11
+ ViewChild ,
12
+ ViewContainerRef ,
19
13
} from '@angular/core' ;
20
- import { Direction , Directionality } from '@angular/cdk/bidi' ;
14
+ import {
15
+ ComponentFixture ,
16
+ TestBed ,
17
+ fakeAsync ,
18
+ flush ,
19
+ tick ,
20
+ waitForAsync ,
21
+ } from '@angular/core/testing' ;
22
+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
21
23
import { dispatchFakeEvent } from '../testing/private' ;
22
- import { ComponentPortal , TemplatePortal , CdkPortal } from '@angular/cdk/portal' ;
23
- import { Location } from '@angular/common' ;
24
- import { SpyLocation } from '@angular/common/testing' ;
25
24
import {
26
25
Overlay ,
26
+ OverlayConfig ,
27
27
OverlayContainer ,
28
28
OverlayModule ,
29
29
OverlayRef ,
30
- OverlayConfig ,
31
30
PositionStrategy ,
32
31
ScrollStrategy ,
33
32
} from './index' ;
34
- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
35
33
36
34
describe ( 'Overlay' , ( ) => {
37
35
let overlay : Overlay ;
@@ -48,8 +46,6 @@ describe('Overlay', () => {
48
46
TestBed . configureTestingModule ( {
49
47
imports : [ OverlayModule , ...imports ] ,
50
48
providers : [
51
- provideZoneChangeDetection ( ) ,
52
- provideZoneChangeDetection ( ) ,
53
49
{
54
50
provide : Directionality ,
55
51
useFactory : ( ) => {
@@ -949,26 +945,23 @@ describe('Overlay', () => {
949
945
. toContain ( 'custom-panel-class' ) ;
950
946
} ) ;
951
947
952
- it ( 'should wait for the overlay to be detached before removing the panelClass' , ( ) => {
948
+ it ( 'should wait for the overlay to be detached before removing the panelClass' , async ( ) => {
953
949
const config = new OverlayConfig ( { panelClass : 'custom-panel-class' } ) ;
954
950
const overlayRef = overlay . create ( config ) ;
955
951
956
952
overlayRef . attach ( componentPortal ) ;
957
- viewContainerFixture . detectChanges ( ) ;
953
+ await viewContainerFixture . whenStable ( ) ;
958
954
959
955
const pane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
960
956
expect ( pane . classList )
961
957
. withContext ( 'Expected class to be added' )
962
958
. toContain ( 'custom-panel-class' ) ;
963
959
964
960
overlayRef . detach ( ) ;
965
- // Stable emits after zone.run
966
- TestBed . inject ( NgZone ) . run ( ( ) => {
967
- viewContainerFixture . detectChanges ( ) ;
968
- expect ( pane . classList )
969
- . withContext ( 'Expected class not to be removed immediately' )
970
- . toContain ( 'custom-panel-class' ) ;
971
- } ) ;
961
+ expect ( pane . classList )
962
+ . withContext ( 'Expected class not to be removed immediately' )
963
+ . toContain ( 'custom-panel-class' ) ;
964
+ await viewContainerFixture . whenStable ( ) ;
972
965
973
966
expect ( pane . classList )
974
967
. not . withContext ( 'Expected class to be removed on stable' )
0 commit comments