@@ -1282,7 +1282,7 @@ describe("animations", function() {
1282
1282
expect ( element ) . not . toHaveClass ( 'green' ) ;
1283
1283
} ) ) ;
1284
1284
1285
- it ( 'should automatically cancel out class-based animations if the element already contains or doesn\' contain the applied classes' ,
1285
+ it ( 'should automatically cancel out class-based animations if the element already contains or doesn\'t contain the applied classes' ,
1286
1286
inject ( function ( $animate , $rootScope ) {
1287
1287
1288
1288
parent . append ( element ) ;
@@ -2191,7 +2191,7 @@ describe("animations", function() {
2191
2191
} ) ;
2192
2192
} ) ;
2193
2193
2194
- describe ( 'when animations are skipped' , function ( ) {
2194
+ describe ( 'when animations are skipped, disabled, or invalid ' , function ( ) {
2195
2195
2196
2196
var overriddenAnimationRunner ;
2197
2197
var capturedAnimation ;
@@ -2240,19 +2240,87 @@ describe("animations", function() {
2240
2240
$rootScope . $digest ( ) ;
2241
2241
$animate . flush ( ) ;
2242
2242
2243
- expect ( moveSpy . callCount ) . toBe ( 1 ) ;
2244
- expect ( moveSpy . calls [ 0 ] . args [ 1 ] ) . toBe ( 'start' ) ;
2243
+ expect ( moveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2244
+ expect ( moveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'start' ) ;
2245
2245
2246
2246
$animate . leave ( element ) ;
2247
2247
$rootScope . $digest ( ) ;
2248
2248
$animate . flush ( ) ;
2249
2249
2250
- expect ( moveSpy . callCount ) . toBe ( 2 ) ;
2251
- expect ( moveSpy . calls [ 1 ] . args [ 1 ] ) . toBe ( 'close' ) ;
2250
+ expect ( moveSpy . calls . count ( ) ) . toBe ( 2 ) ;
2251
+ expect ( moveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'close' ) ;
2252
2252
2253
- expect ( leaveSpy . callCount ) . toBe ( 2 ) ;
2254
- expect ( leaveSpy . calls [ 0 ] . args [ 1 ] ) . toBe ( 'start' ) ;
2255
- expect ( leaveSpy . calls [ 1 ] . args [ 1 ] ) . toBe ( 'close' ) ;
2253
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 2 ) ;
2254
+ expect ( leaveSpy . calls . argsFor ( 0 ) [ 1 ] ) . toBe ( 'start' ) ;
2255
+ expect ( leaveSpy . calls . argsFor ( 1 ) [ 1 ] ) . toBe ( 'close' ) ;
2256
+ } ) ) ;
2257
+
2258
+
2259
+ it ( 'should not trigger callbacks for the previous structural animation if a follow-up structural animation takes over before the postDigest' ,
2260
+ inject ( function ( $animate , $rootScope ) {
2261
+
2262
+ var enterDone = jasmine . createSpy ( 'enter animation done' ) ;
2263
+
2264
+ var enterSpy = jasmine . createSpy ( ) ;
2265
+ var leaveSpy = jasmine . createSpy ( ) ;
2266
+
2267
+ $animate . on ( 'enter' , parent , enterSpy ) ;
2268
+ $animate . on ( 'leave' , parent , leaveSpy ) ;
2269
+
2270
+ $animate . enter ( element , parent ) . done ( enterDone ) ;
2271
+ expect ( enterDone ) . not . toHaveBeenCalled ( ) ;
2272
+
2273
+ var runner = $animate . leave ( element ) ;
2274
+ $animate . flush ( ) ;
2275
+ expect ( enterDone ) . toHaveBeenCalled ( ) ;
2276
+
2277
+ expect ( enterSpy ) . not . toHaveBeenCalled ( ) ;
2278
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2279
+ expect ( leaveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'start' ) ;
2280
+
2281
+ leaveSpy . calls . reset ( ) ;
2282
+ runner . end ( ) ;
2283
+ $animate . flush ( ) ;
2284
+
2285
+ expect ( enterSpy ) . not . toHaveBeenCalled ( ) ;
2286
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2287
+ expect ( leaveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'close' ) ;
2288
+ } ) ) ;
2289
+
2290
+
2291
+ it ( 'should not trigger the callback if animations are disabled on the element' ,
2292
+ inject ( function ( $animate , $rootScope , $rootElement , $document ) {
2293
+
2294
+ var callbackTriggered = false ;
2295
+ var spy = jasmine . createSpy ( 'enter' ) ;
2296
+ $animate . on ( 'enter' , jqLite ( $document [ 0 ] . body ) , spy ) ;
2297
+
2298
+ element = jqLite ( '<div></div>' ) ;
2299
+ $animate . enabled ( element , false ) ;
2300
+ var runner = $animate . enter ( element , $rootElement ) ;
2301
+ $rootScope . $digest ( ) ;
2302
+
2303
+ $animate . flush ( ) ; // Flushes the animation frames for the callbacks
2304
+
2305
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
2306
+ } ) ) ;
2307
+
2308
+
2309
+ it ( 'should not trigger the callbacks if the animation is skipped because there are no class-based animations and no structural animation' ,
2310
+ inject ( function ( $animate , $rootScope ) {
2311
+
2312
+ parent . append ( element ) ;
2313
+ var classSpy = jasmine . createSpy ( 'classChange' ) ;
2314
+ $animate . on ( 'addClass' , element , classSpy ) ;
2315
+ $animate . on ( 'removeClass' , element , classSpy ) ;
2316
+ element . addClass ( 'one three' ) ;
2317
+
2318
+ $animate . addClass ( element , 'one' ) ;
2319
+ $animate . removeClass ( element , 'four' ) ;
2320
+
2321
+ $rootScope . $digest ( ) ;
2322
+ $animate . flush ( ) ;
2323
+ expect ( classSpy ) . not . toHaveBeenCalled ( ) ;
2256
2324
} ) ) ;
2257
2325
2258
2326
} ) ;
0 commit comments