2
2
3
3
describe ( "$animator" , function ( ) {
4
4
5
- var body , element ;
5
+ var body , element , $rootElement ;
6
6
7
7
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 ) ;
10
11
return element ;
11
12
}
12
13
@@ -21,7 +22,18 @@ describe("$animator", function() {
21
22
22
23
describe ( "enable / disable" , function ( ) {
23
24
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
+
25
37
expect ( $animator . enabled ( ) ) . toBe ( true ) ;
26
38
27
39
expect ( $animator . enabled ( 0 ) ) . toBe ( false ) ;
@@ -40,9 +52,10 @@ describe("$animator", function() {
40
52
module ( function ( $animationProvider , $provide ) {
41
53
$provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
42
54
} )
43
- inject ( function ( $animator , $compile , $rootScope ) {
55
+ inject ( function ( $animator , $compile , $rootScope , _$rootElement_ ) {
44
56
animator = $animator ( $rootScope , { } ) ;
45
57
element = $compile ( '<div></div>' ) ( $rootScope ) ;
58
+ $rootElement = _$rootElement_ ;
46
59
} )
47
60
} ) ;
48
61
@@ -131,7 +144,10 @@ describe("$animator", function() {
131
144
animator = $animator ( $rootScope , {
132
145
ngAnimate : '{enter: \'custom\'}'
133
146
} ) ;
147
+
134
148
$rootScope . $digest ( ) ; // re-enable the animations;
149
+ window . setTimeout . expect ( 0 ) . process ( ) ;
150
+
135
151
expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
136
152
animator . enter ( child , element ) ;
137
153
window . setTimeout . expect ( 1 ) . process ( ) ;
@@ -141,7 +157,10 @@ describe("$animator", function() {
141
157
animator = $animator ( $rootScope , {
142
158
ngAnimate : '{leave: \'custom\'}'
143
159
} ) ;
144
- $rootScope . $digest ( ) ;
160
+
161
+ $rootScope . $digest ( ) ; // re-enable the animations;
162
+ window . setTimeout . expect ( 0 ) . process ( ) ;
163
+
145
164
element . append ( child ) ;
146
165
expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
147
166
animator . leave ( child , element ) ;
@@ -150,6 +169,7 @@ describe("$animator", function() {
150
169
} ) ) ;
151
170
152
171
it ( "should animate the move animation event" , inject ( function ( $animator , $compile , $rootScope ) {
172
+ $animator . enabled ( true ) ;
153
173
animator = $animator ( $rootScope , {
154
174
ngAnimate : '{move: \'custom\'}'
155
175
} ) ;
@@ -165,6 +185,7 @@ describe("$animator", function() {
165
185
} ) ) ;
166
186
167
187
it ( "should animate the show animation event" , inject ( function ( $animator , $rootScope ) {
188
+ $animator . enabled ( true ) ;
168
189
animator = $animator ( $rootScope , {
169
190
ngAnimate : '{show: \'custom\'}'
170
191
} ) ;
@@ -178,6 +199,7 @@ describe("$animator", function() {
178
199
} ) ) ;
179
200
180
201
it ( "should animate the hide animation event" , inject ( function ( $animator , $rootScope ) {
202
+ $animator . enabled ( true ) ;
181
203
animator = $animator ( $rootScope , {
182
204
ngAnimate : '{hide: \'custom\'}'
183
205
} ) ;
@@ -192,6 +214,7 @@ describe("$animator", function() {
192
214
193
215
it ( "should assign the ngAnimate string to all events if a string is given" ,
194
216
inject ( function ( $animator , $sniffer , $rootScope ) {
217
+ $animator . enabled ( true ) ;
195
218
if ( ! $sniffer . supportsTransitions ) return ;
196
219
animator = $animator ( $rootScope , {
197
220
ngAnimate : '"custom"'
@@ -237,6 +260,7 @@ describe("$animator", function() {
237
260
} ) ) ;
238
261
239
262
it ( "should run polyfillSetup and return the memento" , inject ( function ( $animator , $rootScope ) {
263
+ $animator . enabled ( true ) ;
240
264
animator = $animator ( $rootScope , {
241
265
ngAnimate : '{show: \'setup-memo\'}'
242
266
} ) ;
@@ -248,6 +272,8 @@ describe("$animator", function() {
248
272
} ) ) ;
249
273
250
274
it ( "should not run if animations are disabled" , inject ( function ( $animator , $rootScope ) {
275
+ $animator . enabled ( true ) ;
276
+ $rootScope . $digest ( ) ; // clear initial animation suppression
251
277
$animator . enabled ( false ) ;
252
278
253
279
animator = $animator ( $rootScope , {
@@ -274,8 +300,10 @@ describe("$animator", function() {
274
300
beforeEach ( function ( ) {
275
301
module ( function ( $animationProvider , $provide ) {
276
302
$provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
277
- return function ( $sniffer ) {
303
+ return function ( $sniffer , _$rootElement_ , $animator ) {
278
304
vendorPrefix = '-' + $sniffer . vendorPrefix + '-' ;
305
+ $rootElement = _$rootElement_ ;
306
+ $animator . enabled ( true ) ;
279
307
} ;
280
308
} )
281
309
} ) ;
@@ -288,8 +316,6 @@ describe("$animator", function() {
288
316
ngAnimate : '{show: \'inline-show\'}'
289
317
} ) ;
290
318
291
- $rootScope . $digest ( ) ; // skip no-animate on first digest.
292
-
293
319
element . css ( 'display' , 'none' ) ;
294
320
expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
295
321
animator . show ( element ) ;
0 commit comments