@@ -1282,7 +1282,7 @@ describe("animations", function() {
12821282 expect ( element ) . not . toHaveClass ( 'green' ) ;
12831283 } ) ) ;
12841284
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' ,
12861286 inject ( function ( $animate , $rootScope ) {
12871287
12881288 parent . append ( element ) ;
@@ -2191,7 +2191,7 @@ describe("animations", function() {
21912191 } ) ;
21922192 } ) ;
21932193
2194- describe ( 'when animations are skipped' , function ( ) {
2194+ describe ( 'when animations are skipped, disabled, or invalid ' , function ( ) {
21952195
21962196 var overriddenAnimationRunner ;
21972197 var capturedAnimation ;
@@ -2240,19 +2240,87 @@ describe("animations", function() {
22402240 $rootScope . $digest ( ) ;
22412241 $animate . flush ( ) ;
22422242
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' ) ;
22452245
22462246 $animate . leave ( element ) ;
22472247 $rootScope . $digest ( ) ;
22482248 $animate . flush ( ) ;
22492249
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' ) ;
22522252
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 ( ) ;
22562324 } ) ) ;
22572325
22582326 } ) ;
0 commit comments