@@ -50,10 +50,11 @@ describe("$animate", function() {
50
50
expect ( element . text ( ) ) . toBe ( '21' ) ;
51
51
} ) ) ;
52
52
53
- it ( "should still perform DOM operations even if animations are disabled" , inject ( function ( $animate ) {
53
+ it ( "should still perform DOM operations even if animations are disabled (post-digest) " , inject ( function ( $animate , $rootScope ) {
54
54
$animate . enabled ( false ) ;
55
55
expect ( element ) . toBeShown ( ) ;
56
56
$animate . addClass ( element , 'ng-hide' ) ;
57
+ $rootScope . $digest ( ) ;
57
58
expect ( element ) . toBeHidden ( ) ;
58
59
} ) ) ;
59
60
@@ -79,15 +80,17 @@ describe("$animate", function() {
79
80
expect ( $animate . cancel ( ) ) . toBeUndefined ( ) ;
80
81
} ) ) ;
81
82
82
- it ( "should add and remove classes on SVG elements" , inject ( function ( $animate ) {
83
+ it ( "should add and remove classes on SVG elements" , inject ( function ( $animate , $rootScope ) {
83
84
if ( ! window . SVGElement ) return ;
84
85
var svg = jqLite ( '<svg><rect></rect></svg>' ) ;
85
86
var rect = svg . children ( ) ;
86
87
$animate . enabled ( false ) ;
87
88
expect ( rect ) . toBeShown ( ) ;
88
89
$animate . addClass ( rect , 'ng-hide' ) ;
90
+ $rootScope . $digest ( ) ;
89
91
expect ( rect ) . toBeHidden ( ) ;
90
92
$animate . removeClass ( rect , 'ng-hide' ) ;
93
+ $rootScope . $digest ( ) ;
91
94
expect ( rect ) . not . toBeHidden ( ) ;
92
95
} ) ) ;
93
96
@@ -101,7 +104,7 @@ describe("$animate", function() {
101
104
} ) ;
102
105
} ) ;
103
106
104
- describe ( 'class API ' , function ( ) {
107
+ describe ( 'CSS class DOM manipulation ' , function ( ) {
105
108
var element ;
106
109
var addClass ;
107
110
var removeClass ;
@@ -138,8 +141,9 @@ describe("$animate", function() {
138
141
} ) ;
139
142
}
140
143
141
- it ( 'should defer class manipulation until end of digest' , inject ( function ( $rootScope , $animate ) {
142
- setupClassManipulationSpies ( ) ;
144
+
145
+ it ( 'should defer class manipulation until end of digest' , inject ( function ( $rootScope , $animate , log ) {
146
+ setupClassManipulationLogger ( log ) ;
143
147
element = jqLite ( '<p>test</p>' ) ;
144
148
145
149
$rootScope . $apply ( function ( ) {
@@ -154,96 +158,28 @@ describe("$animate", function() {
154
158
$animate . setClass ( element , 'test-class3' , 'test-class4' ) ;
155
159
expect ( element ) . not . toHaveClass ( 'test-class3' ) ;
156
160
expect ( element ) . not . toHaveClass ( 'test-class4' ) ;
161
+ expect ( log ) . toEqual ( [ ] ) ;
157
162
} ) ;
158
163
159
164
expect ( element ) . not . toHaveClass ( 'test-class1' ) ;
160
165
expect ( element ) . not . toHaveClass ( 'test-class4' ) ;
161
166
expect ( element ) . toHaveClass ( 'test-class2' ) ;
162
167
expect ( element ) . toHaveClass ( 'test-class3' ) ;
168
+ expect ( log ) . toEqual ( [ 'addClass(test-class2 test-class3)' ] ) ;
163
169
expect ( addClass . callCount ) . toBe ( 1 ) ;
164
170
expect ( removeClass . callCount ) . toBe ( 0 ) ;
165
171
} ) ) ;
166
172
167
173
168
- it ( 'should perform class manipulation immediately outside of digest' , inject ( function ( $rootScope , $animate ) {
169
- setupClassManipulationSpies ( ) ;
170
- element = jqLite ( '<p>test</p>' ) ;
171
-
172
- $animate . addClass ( element , 'test-class1' ) ;
173
- expect ( element ) . toHaveClass ( 'test-class1' ) ;
174
-
175
- $animate . removeClass ( element , 'test-class1' ) ;
176
- expect ( element ) . not . toHaveClass ( 'test-class1' ) ;
177
-
178
- $animate . addClass ( element , 'test-class2' ) ;
179
- expect ( element ) . toHaveClass ( 'test-class2' ) ;
180
-
181
- $animate . setClass ( element , 'test-class3' , 'test-class4' ) ;
182
- expect ( element ) . toHaveClass ( 'test-class3' ) ;
183
- expect ( element ) . not . toHaveClass ( 'test-class4' ) ;
184
-
185
- expect ( element ) . not . toHaveClass ( 'test-class1' ) ;
186
- expect ( element ) . toHaveClass ( 'test-class2' ) ;
187
- expect ( addClass . callCount ) . toBe ( 3 ) ;
188
- expect ( removeClass . callCount ) . toBe ( 1 ) ;
189
- } ) ) ;
190
-
191
-
192
- it ( 'should perform class manipulation in expected order at end of digest' , inject ( function ( $rootScope , $animate , log ) {
193
- element = jqLite ( '<p class="test-class3">test</p>' ) ;
194
-
195
- setupClassManipulationLogger ( log ) ;
196
-
197
- $rootScope . $apply ( function ( ) {
198
- $animate . addClass ( element , 'test-class1' ) ;
199
- $animate . addClass ( element , 'test-class2' ) ;
200
- $animate . removeClass ( element , 'test-class1' ) ;
201
- $animate . removeClass ( element , 'test-class3' ) ;
202
- $animate . addClass ( element , 'test-class3' ) ;
203
- } ) ;
204
- expect ( log ) . toEqual ( [ 'addClass(test-class2)' ] ) ;
205
- } ) ) ;
206
-
207
-
208
- it ( 'should perform class manipulation in expected order outside of digest' , inject ( function ( $rootScope , $animate , log ) {
209
- element = jqLite ( '<p class="test-class3">test</p>' ) ;
210
-
211
- setupClassManipulationLogger ( log ) ;
212
-
213
- $animate . addClass ( element , 'test-class1' ) ;
214
- $animate . addClass ( element , 'test-class2' ) ;
215
- $animate . removeClass ( element , 'test-class1' ) ;
216
- $animate . removeClass ( element , 'test-class3' ) ;
217
- $animate . addClass ( element , 'test-class3' ) ;
218
-
219
- expect ( log ) . toEqual ( [
220
- 'addClass(test-class1)' ,
221
- 'addClass(test-class2)' ,
222
- 'removeClass(test-class1)' ,
223
- 'removeClass(test-class3)' ,
224
- 'addClass(test-class3)' ] ) ;
225
- } ) ) ;
226
-
227
-
228
- it ( 'should return a promise which is resolved on a different turn' , inject ( function ( log , $animate , $browser , $rootScope ) {
174
+ it ( 'should return a promise which is resolved on a different turn digest' , inject ( function ( log , $animate , $browser , $rootScope ) {
229
175
element = jqLite ( '<p class="test2">test</p>' ) ;
230
176
231
177
$animate . addClass ( element , 'test1' ) . then ( log . fn ( 'addClass(test1)' ) ) ;
232
178
$animate . removeClass ( element , 'test2' ) . then ( log . fn ( 'removeClass(test2)' ) ) ;
233
179
180
+ $rootScope . $digest ( ) ;
234
181
$browser . defer . flush ( ) ;
235
182
expect ( log ) . toEqual ( [ 'addClass(test1)' , 'removeClass(test2)' ] ) ;
236
-
237
- log . reset ( ) ;
238
- element = jqLite ( '<p class="test4">test</p>' ) ;
239
-
240
- $rootScope . $apply ( function ( ) {
241
- $animate . addClass ( element , 'test3' ) . then ( log . fn ( 'addClass(test3)' ) ) ;
242
- $animate . removeClass ( element , 'test4' ) . then ( log . fn ( 'removeClass(test4)' ) ) ;
243
- } ) ;
244
-
245
- $browser . defer . flush ( ) ;
246
- expect ( log ) . toEqual ( [ 'addClass(test3)' , 'removeClass(test4)' ] ) ;
247
183
} ) ) ;
248
184
249
185
@@ -274,29 +210,27 @@ describe("$animate", function() {
274
210
} ) ) ;
275
211
276
212
277
- it ( 'should perform class manipulation immediately outside of digest for SVG' , inject ( function ( $rootScope , $animate ) {
213
+ it ( 'should defer class manipulation until digest outside of digest for SVG' , inject ( function ( $rootScope , $animate , log ) {
278
214
if ( ! window . SVGElement ) return ;
279
- setupClassManipulationSpies ( ) ;
215
+ setupClassManipulationLogger ( log ) ;
280
216
element = jqLite ( '<svg><g></g></svg>' ) ;
281
217
var target = element . children ( ) . eq ( 0 ) ;
282
218
283
219
$animate . addClass ( target , 'test-class1' ) ;
284
- expect ( target ) . toHaveClass ( 'test-class1' ) ;
285
-
286
220
$animate . removeClass ( target , 'test-class1' ) ;
287
- expect ( target ) . not . toHaveClass ( 'test-class1' ) ;
288
-
289
221
$animate . addClass ( target , 'test-class2' ) ;
290
- expect ( target ) . toHaveClass ( 'test-class2' ) ;
291
-
292
222
$animate . setClass ( target , 'test-class3' , 'test-class4' ) ;
293
- expect ( target ) . toHaveClass ( 'test-class3' ) ;
294
- expect ( target ) . not . toHaveClass ( 'test-class4' ) ;
295
223
224
+ expect ( log ) . toEqual ( [ ] ) ;
225
+
226
+ $rootScope . $digest ( ) ;
227
+
228
+ expect ( log ) . toEqual ( [ 'addClass(test-class2 test-class3)' ] ) ;
296
229
expect ( target ) . not . toHaveClass ( 'test-class1' ) ;
297
230
expect ( target ) . toHaveClass ( 'test-class2' ) ;
298
- expect ( addClass . callCount ) . toBe ( 3 ) ;
299
- expect ( removeClass . callCount ) . toBe ( 1 ) ;
231
+ expect ( target ) . toHaveClass ( 'test-class3' ) ;
232
+ expect ( addClass . callCount ) . toBe ( 1 ) ;
233
+ expect ( removeClass . callCount ) . toBe ( 0 ) ;
300
234
} ) ) ;
301
235
302
236
@@ -316,27 +250,5 @@ describe("$animate", function() {
316
250
} ) ;
317
251
expect ( log ) . toEqual ( [ 'addClass(test-class2)' ] ) ;
318
252
} ) ) ;
319
-
320
-
321
- it ( 'should perform class manipulation in expected order outside of digest for SVG' , inject ( function ( $rootScope , $animate , log ) {
322
- if ( ! window . SVGElement ) return ;
323
- element = jqLite ( '<svg><g class="test-class3"></g></svg>' ) ;
324
- var target = element . children ( ) . eq ( 0 ) ;
325
-
326
- setupClassManipulationLogger ( log ) ;
327
-
328
- $animate . addClass ( target , 'test-class1' ) ;
329
- $animate . addClass ( target , 'test-class2' ) ;
330
- $animate . removeClass ( target , 'test-class1' ) ;
331
- $animate . removeClass ( target , 'test-class3' ) ;
332
- $animate . addClass ( target , 'test-class3' ) ;
333
-
334
- expect ( log ) . toEqual ( [
335
- 'addClass(test-class1)' ,
336
- 'addClass(test-class2)' ,
337
- 'removeClass(test-class1)' ,
338
- 'removeClass(test-class3)' ,
339
- 'addClass(test-class3)' ] ) ;
340
- } ) ) ;
341
253
} ) ;
342
254
} ) ;
0 commit comments