1- import {
2- waitForAsync ,
3- fakeAsync ,
4- tick ,
5- ComponentFixture ,
6- inject ,
7- TestBed ,
8- } from '@angular/core/testing' ;
1+ import { waitForAsync , fakeAsync , tick , ComponentFixture , TestBed } from '@angular/core/testing' ;
92import {
103 Component ,
114 ViewChild ,
@@ -14,6 +7,7 @@ import {
147 Injectable ,
158 EventEmitter ,
169 NgZone ,
10+ Type ,
1711} from '@angular/core' ;
1812import { Direction , Directionality } from '@angular/cdk/bidi' ;
1913import { MockNgZone , dispatchFakeEvent } from '../testing/private' ;
@@ -30,6 +24,7 @@ import {
3024 ScrollStrategy ,
3125} from './index' ;
3226import { OverlayReference } from './overlay-reference' ;
27+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
3328
3429describe ( 'Overlay' , ( ) => {
3530 let overlay : Overlay ;
@@ -42,10 +37,10 @@ describe('Overlay', () => {
4237 let zone : MockNgZone ;
4338 let mockLocation : SpyLocation ;
4439
45- beforeEach ( waitForAsync ( ( ) => {
40+ function setup ( imports : Type < unknown > [ ] = [ ] ) {
4641 dir = 'ltr' ;
4742 TestBed . configureTestingModule ( {
48- imports : [ OverlayModule , PortalModule ] ,
43+ imports : [ OverlayModule , PortalModule , ... imports ] ,
4944 declarations : [ PizzaMsg , TestComponentWithTemplatePortals ] ,
5045 providers : [
5146 {
@@ -66,27 +61,25 @@ describe('Overlay', () => {
6661 } ,
6762 ] ,
6863 } ) . compileComponents ( ) ;
69- } ) ) ;
7064
71- beforeEach ( inject (
72- [ Overlay , OverlayContainer , Location ] ,
73- ( o : Overlay , oc : OverlayContainer , l : Location ) => {
74- overlay = o ;
75- overlayContainer = oc ;
76- overlayContainerElement = oc . getContainerElement ( ) ;
77-
78- const fixture = TestBed . createComponent ( TestComponentWithTemplatePortals ) ;
79- fixture . detectChanges ( ) ;
80- templatePortal = fixture . componentInstance . templatePortal ;
81- componentPortal = new ComponentPortal ( PizzaMsg , fixture . componentInstance . viewContainerRef ) ;
82- viewContainerFixture = fixture ;
83- mockLocation = l as SpyLocation ;
84- } ,
85- ) ) ;
86-
87- afterEach ( ( ) => {
65+ overlay = TestBed . inject ( Overlay ) ;
66+ overlayContainer = TestBed . inject ( OverlayContainer ) ;
67+ overlayContainerElement = overlayContainer . getContainerElement ( ) ;
68+
69+ const fixture = TestBed . createComponent ( TestComponentWithTemplatePortals ) ;
70+ fixture . detectChanges ( ) ;
71+ templatePortal = fixture . componentInstance . templatePortal ;
72+ componentPortal = new ComponentPortal ( PizzaMsg , fixture . componentInstance . viewContainerRef ) ;
73+ viewContainerFixture = fixture ;
74+ mockLocation = TestBed . inject ( Location ) as SpyLocation ;
75+ }
76+
77+ function cleanup ( ) {
8878 overlayContainer . ngOnDestroy ( ) ;
89- } ) ;
79+ }
80+
81+ beforeEach ( waitForAsync ( setup ) ) ;
82+ afterEach ( cleanup ) ;
9083
9184 it ( 'should load a component into an overlay' , ( ) => {
9285 let overlayRef = overlay . create ( ) ;
@@ -867,6 +860,20 @@ describe('Overlay', () => {
867860 backdrop . click ( ) ;
868861 expect ( backdropClickHandler ) . toHaveBeenCalledTimes ( 1 ) ;
869862 } ) ;
863+
864+ it ( 'should set a class on the backdrop when animations are disabled' , ( ) => {
865+ cleanup ( ) ;
866+ TestBed . resetTestingModule ( ) ;
867+ setup ( [ NoopAnimationsModule ] ) ;
868+
869+ let overlayRef = overlay . create ( config ) ;
870+ overlayRef . attach ( componentPortal ) ;
871+
872+ viewContainerFixture . detectChanges ( ) ;
873+ let backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
874+
875+ expect ( backdrop . classList ) . toContain ( 'cdk-overlay-backdrop-noop-animation' ) ;
876+ } ) ;
870877 } ) ;
871878
872879 describe ( 'panelClass' , ( ) => {
0 commit comments