22
33describe ( "$animator" , function ( ) {
44
5- var body , element ;
5+ var body , element , $rootElement ;
66
77 function html ( html ) {
8- body . html ( html ) ;
9- element = body . children ( ) . eq ( 0 ) ;
8+ body . append ( $rootElement ) ;
9+ $rootElement . html ( html ) ;
10+ element = $rootElement . children ( ) . eq ( 0 ) ;
1011 return element ;
1112 }
1213
@@ -21,7 +22,18 @@ describe("$animator", function() {
2122
2223 describe ( "enable / disable" , function ( ) {
2324
24- it ( "should disable and enable the animations" , inject ( function ( $animator ) {
25+ beforeEach ( function ( ) {
26+ module ( function ( $animationProvider , $provide ) {
27+ $provide . value ( '$window' , angular . mock . createMockWindow ( ) ) ;
28+ } ) ;
29+ } ) ;
30+
31+ it ( "should disable and enable the animations" , inject ( function ( $animator , $rootScope , $window ) {
32+ expect ( $animator . enabled ( ) ) . toBe ( false ) ;
33+
34+ $rootScope . $digest ( ) ;
35+ $window . setTimeout . expect ( 0 ) . process ( ) ;
36+
2537 expect ( $animator . enabled ( ) ) . toBe ( true ) ;
2638
2739 expect ( $animator . enabled ( 0 ) ) . toBe ( false ) ;
@@ -40,9 +52,10 @@ describe("$animator", function() {
4052 module ( function ( $animationProvider , $provide ) {
4153 $provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
4254 } )
43- inject ( function ( $animator , $compile , $rootScope ) {
55+ inject ( function ( $animator , $compile , $rootScope , _$rootElement_ ) {
4456 animator = $animator ( $rootScope , { } ) ;
4557 element = $compile ( '<div></div>' ) ( $rootScope ) ;
58+ $rootElement = _$rootElement_ ;
4659 } )
4760 } ) ;
4861
@@ -131,7 +144,10 @@ describe("$animator", function() {
131144 animator = $animator ( $rootScope , {
132145 ngAnimate : '{enter: \'custom\'}'
133146 } ) ;
147+
134148 $rootScope . $digest ( ) ; // re-enable the animations;
149+ window . setTimeout . expect ( 0 ) . process ( ) ;
150+
135151 expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
136152 animator . enter ( child , element ) ;
137153 window . setTimeout . expect ( 1 ) . process ( ) ;
@@ -141,7 +157,10 @@ describe("$animator", function() {
141157 animator = $animator ( $rootScope , {
142158 ngAnimate : '{leave: \'custom\'}'
143159 } ) ;
144- $rootScope . $digest ( ) ;
160+
161+ $rootScope . $digest ( ) ; // re-enable the animations;
162+ window . setTimeout . expect ( 0 ) . process ( ) ;
163+
145164 element . append ( child ) ;
146165 expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
147166 animator . leave ( child , element ) ;
@@ -150,6 +169,7 @@ describe("$animator", function() {
150169 } ) ) ;
151170
152171 it ( "should animate the move animation event" , inject ( function ( $animator , $compile , $rootScope ) {
172+ $animator . enabled ( true ) ;
153173 animator = $animator ( $rootScope , {
154174 ngAnimate : '{move: \'custom\'}'
155175 } ) ;
@@ -165,6 +185,7 @@ describe("$animator", function() {
165185 } ) ) ;
166186
167187 it ( "should animate the show animation event" , inject ( function ( $animator , $rootScope ) {
188+ $animator . enabled ( true ) ;
168189 animator = $animator ( $rootScope , {
169190 ngAnimate : '{show: \'custom\'}'
170191 } ) ;
@@ -178,6 +199,7 @@ describe("$animator", function() {
178199 } ) ) ;
179200
180201 it ( "should animate the hide animation event" , inject ( function ( $animator , $rootScope ) {
202+ $animator . enabled ( true ) ;
181203 animator = $animator ( $rootScope , {
182204 ngAnimate : '{hide: \'custom\'}'
183205 } ) ;
@@ -192,6 +214,7 @@ describe("$animator", function() {
192214
193215 it ( "should assign the ngAnimate string to all events if a string is given" ,
194216 inject ( function ( $animator , $sniffer , $rootScope ) {
217+ $animator . enabled ( true ) ;
195218 if ( ! $sniffer . supportsTransitions ) return ;
196219 animator = $animator ( $rootScope , {
197220 ngAnimate : '"custom"'
@@ -237,6 +260,7 @@ describe("$animator", function() {
237260 } ) ) ;
238261
239262 it ( "should run polyfillSetup and return the memento" , inject ( function ( $animator , $rootScope ) {
263+ $animator . enabled ( true ) ;
240264 animator = $animator ( $rootScope , {
241265 ngAnimate : '{show: \'setup-memo\'}'
242266 } ) ;
@@ -248,6 +272,8 @@ describe("$animator", function() {
248272 } ) ) ;
249273
250274 it ( "should not run if animations are disabled" , inject ( function ( $animator , $rootScope ) {
275+ $animator . enabled ( true ) ;
276+ $rootScope . $digest ( ) ; // clear initial animation suppression
251277 $animator . enabled ( false ) ;
252278
253279 animator = $animator ( $rootScope , {
@@ -274,8 +300,10 @@ describe("$animator", function() {
274300 beforeEach ( function ( ) {
275301 module ( function ( $animationProvider , $provide ) {
276302 $provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
277- return function ( $sniffer ) {
303+ return function ( $sniffer , _$rootElement_ , $animator ) {
278304 vendorPrefix = '-' + $sniffer . vendorPrefix + '-' ;
305+ $rootElement = _$rootElement_ ;
306+ $animator . enabled ( true ) ;
279307 } ;
280308 } )
281309 } ) ;
@@ -288,8 +316,6 @@ describe("$animator", function() {
288316 ngAnimate : '{show: \'inline-show\'}'
289317 } ) ;
290318
291- $rootScope . $digest ( ) ; // skip no-animate on first digest.
292-
293319 element . css ( 'display' , 'none' ) ;
294320 expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
295321 animator . show ( element ) ;
0 commit comments