@@ -9,97 +9,121 @@ import {animate, style, transition, trigger} from '@angular/animations';
99import { ɵAnimationEngine } from '@angular/animations/browser' ;
1010import { Component } from '@angular/core' ;
1111import { TestBed } from '@angular/core/testing' ;
12- import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
12+ import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
1313
14- {
15- describe ( 'NoopAnimationsModule' , ( ) => {
16- beforeEach ( ( ) => {
17- TestBed . configureTestingModule ( { imports : [ NoopAnimationsModule ] } ) ;
18- } ) ;
14+ describe ( 'NoopAnimationsModule' , ( ) => {
15+ beforeEach ( ( ) => {
16+ TestBed . configureTestingModule ( { imports : [ NoopAnimationsModule ] } ) ;
17+ } ) ;
18+
19+ noopAnimationTests ( ) ;
20+ } ) ;
21+
22+ describe ( 'BrowserAnimationsModule with disableAnimations = true' , ( ) => {
23+ beforeEach ( ( ) => {
24+ TestBed . configureTestingModule (
25+ { imports : [ BrowserAnimationsModule . withConfig ( { disableAnimations : true } ) ] } ) ;
26+ } ) ;
27+
28+ noopAnimationTests ( ) ;
29+ } ) ;
30+
31+
32+ function noopAnimationTests ( ) {
33+ it ( 'should flush and fire callbacks when the zone becomes stable' , ( async ) => {
34+ // This test is only meant to be run inside the browser.
35+ if ( isNode ) {
36+ async ( ) ;
37+ return ;
38+ }
1939
20- it ( 'should flush and fire callbacks when the zone becomes stable' , ( async ) => {
21- @Component ( {
22- selector : 'my-cmp' ,
23- template :
24- '<div [@myAnimation]="exp" (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>' ,
25- animations : [ trigger (
26- 'myAnimation' ,
27- [ transition (
28- '* => state' , [ style ( { 'opacity' : '0' } ) , animate ( 500 , style ( { 'opacity' : '1' } ) ) ] ) ] ) ] ,
29- } )
30- class Cmp {
31- exp : any ;
32- startEvent : any ;
33- doneEvent : any ;
34- onStart ( event : any ) {
35- this . startEvent = event ;
36- }
37- onDone ( event : any ) {
38- this . doneEvent = event ;
39- }
40+ @Component ( {
41+ selector : 'my-cmp' ,
42+ template :
43+ '<div [@myAnimation]="exp" (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>' ,
44+ animations : [ trigger (
45+ 'myAnimation' ,
46+ [ transition (
47+ '* => state' , [ style ( { 'opacity' : '0' } ) , animate ( 500 , style ( { 'opacity' : '1' } ) ) ] ) ] ) ] ,
48+ } )
49+ class Cmp {
50+ exp : any ;
51+ startEvent : any ;
52+ doneEvent : any ;
53+ onStart ( event : any ) {
54+ this . startEvent = event ;
4055 }
56+ onDone ( event : any ) {
57+ this . doneEvent = event ;
58+ }
59+ }
4160
42- TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
61+ TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
4362
44- const fixture = TestBed . createComponent ( Cmp ) ;
45- const cmp = fixture . componentInstance ;
46- cmp . exp = 'state' ;
47- fixture . detectChanges ( ) ;
48- fixture . whenStable ( ) . then ( ( ) => {
49- expect ( cmp . startEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
50- expect ( cmp . startEvent . phaseName ) . toEqual ( 'start' ) ;
51- expect ( cmp . doneEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
52- expect ( cmp . doneEvent . phaseName ) . toEqual ( 'done' ) ;
53- async ( ) ;
54- } ) ;
63+ const fixture = TestBed . createComponent ( Cmp ) ;
64+ const cmp = fixture . componentInstance ;
65+ cmp . exp = 'state' ;
66+ fixture . detectChanges ( ) ;
67+ fixture . whenStable ( ) . then ( ( ) => {
68+ expect ( cmp . startEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
69+ expect ( cmp . startEvent . phaseName ) . toEqual ( 'start' ) ;
70+ expect ( cmp . doneEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
71+ expect ( cmp . doneEvent . phaseName ) . toEqual ( 'done' ) ;
72+ async ( ) ;
5573 } ) ;
74+ } ) ;
5675
57- it ( 'should handle leave animation callbacks even if the element is destroyed in the process' ,
58- ( async ) => {
59- @Component ( {
60- selector : 'my-cmp' ,
61- template :
62- '<div *ngIf="exp" @myAnimation (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>' ,
63- animations : [ trigger (
64- 'myAnimation' ,
65- [ transition (
66- ':leave' , [ style ( { 'opacity' : '0' } ) , animate ( 500 , style ( { 'opacity' : '1' } ) ) ] ) ] ) ] ,
67- } )
68- class Cmp {
69- exp : any ;
70- startEvent : any ;
71- doneEvent : any ;
72- onStart ( event : any ) {
73- this . startEvent = event ;
74- }
75- onDone ( event : any ) {
76- this . doneEvent = event ;
77- }
76+ it ( 'should handle leave animation callbacks even if the element is destroyed in the process' ,
77+ ( async ) => {
78+ // This test is only meant to be run inside the browser.
79+ if ( isNode ) {
80+ async ( ) ;
81+ return ;
82+ }
83+
84+ @Component ( {
85+ selector : 'my-cmp' ,
86+ template :
87+ '<div *ngIf="exp" @myAnimation (@myAnimation.start)="onStart($event)" (@myAnimation.done)="onDone($event)"></div>' ,
88+ animations : [ trigger (
89+ 'myAnimation' ,
90+ [ transition (
91+ ':leave' , [ style ( { 'opacity' : '0' } ) , animate ( 500 , style ( { 'opacity' : '1' } ) ) ] ) ] ) ] ,
92+ } )
93+ class Cmp {
94+ exp : any ;
95+ startEvent : any ;
96+ doneEvent : any ;
97+ onStart ( event : any ) {
98+ this . startEvent = event ;
99+ }
100+ onDone ( event : any ) {
101+ this . doneEvent = event ;
78102 }
103+ }
79104
80- TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
81- const engine = TestBed . inject ( ɵAnimationEngine ) ;
82- const fixture = TestBed . createComponent ( Cmp ) ;
83- const cmp = fixture . componentInstance ;
105+ TestBed . configureTestingModule ( { declarations : [ Cmp ] } ) ;
106+ const engine = TestBed . inject ( ɵAnimationEngine ) ;
107+ const fixture = TestBed . createComponent ( Cmp ) ;
108+ const cmp = fixture . componentInstance ;
84109
85- cmp . exp = true ;
110+ cmp . exp = true ;
111+ fixture . detectChanges ( ) ;
112+ fixture . whenStable ( ) . then ( ( ) => {
113+ cmp . startEvent = null ;
114+ cmp . doneEvent = null ;
115+
116+ cmp . exp = false ;
86117 fixture . detectChanges ( ) ;
87118 fixture . whenStable ( ) . then ( ( ) => {
88- cmp . startEvent = null ;
89- cmp . doneEvent = null ;
90-
91- cmp . exp = false ;
92- fixture . detectChanges ( ) ;
93- fixture . whenStable ( ) . then ( ( ) => {
94- expect ( cmp . startEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
95- expect ( cmp . startEvent . phaseName ) . toEqual ( 'start' ) ;
96- expect ( cmp . startEvent . toState ) . toEqual ( 'void' ) ;
97- expect ( cmp . doneEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
98- expect ( cmp . doneEvent . phaseName ) . toEqual ( 'done' ) ;
99- expect ( cmp . doneEvent . toState ) . toEqual ( 'void' ) ;
100- async ( ) ;
101- } ) ;
119+ expect ( cmp . startEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
120+ expect ( cmp . startEvent . phaseName ) . toEqual ( 'start' ) ;
121+ expect ( cmp . startEvent . toState ) . toEqual ( 'void' ) ;
122+ expect ( cmp . doneEvent . triggerName ) . toEqual ( 'myAnimation' ) ;
123+ expect ( cmp . doneEvent . phaseName ) . toEqual ( 'done' ) ;
124+ expect ( cmp . doneEvent . toState ) . toEqual ( 'void' ) ;
125+ async ( ) ;
102126 } ) ;
103127 } ) ;
104- } ) ;
128+ } ) ;
105129}
0 commit comments