@@ -1256,7 +1256,7 @@ describe("animations", function() {
1256
1256
expect ( element ) . not . toHaveClass ( 'green' ) ;
1257
1257
} ) ) ;
1258
1258
1259
- it ( 'should automatically cancel out class-based animations if the element already contains or doesn\' contain the applied classes' ,
1259
+ it ( 'should automatically cancel out class-based animations if the element already contains or doesn\'t contain the applied classes' ,
1260
1260
inject ( function ( $animate , $rootScope ) {
1261
1261
1262
1262
parent . append ( element ) ;
@@ -2137,7 +2137,7 @@ describe("animations", function() {
2137
2137
} ) ;
2138
2138
} ) ;
2139
2139
2140
- describe ( 'when animations are skipped' , function ( ) {
2140
+ describe ( 'when animations are skipped, disabled, or invalid ' , function ( ) {
2141
2141
2142
2142
var overriddenAnimationRunner ;
2143
2143
var capturedAnimation ;
@@ -2186,19 +2186,87 @@ describe("animations", function() {
2186
2186
$rootScope . $digest ( ) ;
2187
2187
$animate . flush ( ) ;
2188
2188
2189
- expect ( moveSpy . callCount ) . toBe ( 1 ) ;
2190
- expect ( moveSpy . calls [ 0 ] . args [ 1 ] ) . toBe ( 'start' ) ;
2189
+ expect ( moveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2190
+ expect ( moveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'start' ) ;
2191
2191
2192
2192
$animate . leave ( element ) ;
2193
2193
$rootScope . $digest ( ) ;
2194
2194
$animate . flush ( ) ;
2195
2195
2196
- expect ( moveSpy . callCount ) . toBe ( 2 ) ;
2197
- expect ( moveSpy . calls [ 1 ] . args [ 1 ] ) . toBe ( 'close' ) ;
2196
+ expect ( moveSpy . calls . count ( ) ) . toBe ( 2 ) ;
2197
+ expect ( moveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'close' ) ;
2198
2198
2199
- expect ( leaveSpy . callCount ) . toBe ( 2 ) ;
2200
- expect ( leaveSpy . calls [ 0 ] . args [ 1 ] ) . toBe ( 'start' ) ;
2201
- expect ( leaveSpy . calls [ 1 ] . args [ 1 ] ) . toBe ( 'close' ) ;
2199
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 2 ) ;
2200
+ expect ( leaveSpy . calls . argsFor ( 0 ) [ 1 ] ) . toBe ( 'start' ) ;
2201
+ expect ( leaveSpy . calls . argsFor ( 1 ) [ 1 ] ) . toBe ( 'close' ) ;
2202
+ } ) ) ;
2203
+
2204
+
2205
+ it ( 'should not trigger callbacks for the previous structural animation if a follow-up structural animation takes over before the postDigest' ,
2206
+ inject ( function ( $animate , $rootScope ) {
2207
+
2208
+ var enterDone = jasmine . createSpy ( 'enter animation done' ) ;
2209
+
2210
+ var enterSpy = jasmine . createSpy ( ) ;
2211
+ var leaveSpy = jasmine . createSpy ( ) ;
2212
+
2213
+ $animate . on ( 'enter' , parent , enterSpy ) ;
2214
+ $animate . on ( 'leave' , parent , leaveSpy ) ;
2215
+
2216
+ $animate . enter ( element , parent ) . done ( enterDone ) ;
2217
+ expect ( enterDone ) . not . toHaveBeenCalled ( ) ;
2218
+
2219
+ var runner = $animate . leave ( element ) ;
2220
+ $animate . flush ( ) ;
2221
+ expect ( enterDone ) . toHaveBeenCalled ( ) ;
2222
+
2223
+ expect ( enterSpy ) . not . toHaveBeenCalled ( ) ;
2224
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2225
+ expect ( leaveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'start' ) ;
2226
+
2227
+ leaveSpy . calls . reset ( ) ;
2228
+ runner . end ( ) ;
2229
+ $animate . flush ( ) ;
2230
+
2231
+ expect ( enterSpy ) . not . toHaveBeenCalled ( ) ;
2232
+ expect ( leaveSpy . calls . count ( ) ) . toBe ( 1 ) ;
2233
+ expect ( leaveSpy . calls . mostRecent ( ) . args [ 1 ] ) . toBe ( 'close' ) ;
2234
+ } ) ) ;
2235
+
2236
+
2237
+ it ( 'should not trigger the callback if animations are disabled on the element' ,
2238
+ inject ( function ( $animate , $rootScope , $rootElement , $document ) {
2239
+
2240
+ var callbackTriggered = false ;
2241
+ var spy = jasmine . createSpy ( 'enter' ) ;
2242
+ $animate . on ( 'enter' , jqLite ( $document [ 0 ] . body ) , spy ) ;
2243
+
2244
+ element = jqLite ( '<div></div>' ) ;
2245
+ $animate . enabled ( element , false ) ;
2246
+ var runner = $animate . enter ( element , $rootElement ) ;
2247
+ $rootScope . $digest ( ) ;
2248
+
2249
+ $animate . flush ( ) ; // Flushes the animation frames for the callbacks
2250
+
2251
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
2252
+ } ) ) ;
2253
+
2254
+
2255
+ it ( 'should not trigger the callbacks if the animation is skipped because there are no class-based animations and no structural animation' ,
2256
+ inject ( function ( $animate , $rootScope ) {
2257
+
2258
+ parent . append ( element ) ;
2259
+ var classSpy = jasmine . createSpy ( 'classChange' ) ;
2260
+ $animate . on ( 'addClass' , element , classSpy ) ;
2261
+ $animate . on ( 'removeClass' , element , classSpy ) ;
2262
+ element . addClass ( 'one three' ) ;
2263
+
2264
+ $animate . addClass ( element , 'one' ) ;
2265
+ $animate . removeClass ( element , 'four' ) ;
2266
+
2267
+ $rootScope . $digest ( ) ;
2268
+ $animate . flush ( ) ;
2269
+ expect ( classSpy ) . not . toHaveBeenCalled ( ) ;
2202
2270
} ) ) ;
2203
2271
2204
2272
} ) ;
0 commit comments