@@ -295,6 +295,135 @@ describe('animations', function() {
295
295
} ) ;
296
296
} ) ;
297
297
298
+ describe ( 'customFilter()' , function ( ) {
299
+ it ( 'should be `null` by default' , module ( function ( $animateProvider ) {
300
+ expect ( $animateProvider . customFilter ( ) ) . toBeNull ( ) ;
301
+ } ) ) ;
302
+
303
+ it ( 'should clear the `customFilter` if no function is passed' ,
304
+ module ( function ( $animateProvider ) {
305
+ $animateProvider . customFilter ( angular . noop ) ;
306
+ expect ( $animateProvider . customFilter ( ) ) . toEqual ( jasmine . any ( Function ) ) ;
307
+
308
+ $animateProvider . customFilter ( null ) ;
309
+ expect ( $animateProvider . customFilter ( ) ) . toBeNull ( ) ;
310
+
311
+ $animateProvider . customFilter ( angular . noop ) ;
312
+ expect ( $animateProvider . customFilter ( ) ) . toEqual ( jasmine . any ( Function ) ) ;
313
+
314
+ $animateProvider . customFilter ( { } ) ;
315
+ expect ( $animateProvider . customFilter ( ) ) . toBeNull ( ) ;
316
+ } )
317
+ ) ;
318
+
319
+ it ( 'should only perform animations for which the function returns a truthy value' ,
320
+ function ( ) {
321
+ var animationsAllowed = false ;
322
+
323
+ module ( function ( $animateProvider ) {
324
+ $animateProvider . customFilter ( function ( ) { return animationsAllowed ; } ) ;
325
+ } ) ;
326
+
327
+ inject ( function ( $animate , $rootScope ) {
328
+ $animate . enter ( element , parent ) ;
329
+ $rootScope . $digest ( ) ;
330
+ expect ( capturedAnimation ) . toBeNull ( ) ;
331
+
332
+ $animate . leave ( element , parent ) ;
333
+ $rootScope . $digest ( ) ;
334
+ expect ( capturedAnimation ) . toBeNull ( ) ;
335
+
336
+ animationsAllowed = true ;
337
+
338
+ $animate . enter ( element , parent ) ;
339
+ $rootScope . $digest ( ) ;
340
+ expect ( capturedAnimation ) . not . toBeNull ( ) ;
341
+
342
+ capturedAnimation = null ;
343
+
344
+ $animate . leave ( element , parent ) ;
345
+ $rootScope . $digest ( ) ;
346
+ expect ( capturedAnimation ) . not . toBeNull ( ) ;
347
+ } ) ;
348
+ }
349
+ ) ;
350
+
351
+ it ( 'should only perform animations for which the function returns a truthy value (SVG)' ,
352
+ function ( ) {
353
+ var animationsAllowed = false ;
354
+
355
+ module ( function ( $animateProvider ) {
356
+ $animateProvider . customFilter ( function ( ) { return animationsAllowed ; } ) ;
357
+ } ) ;
358
+
359
+ inject ( function ( $animate , $compile , $rootScope ) {
360
+ var svgElement = $compile ( '<svg class="element"></svg>' ) ( $rootScope ) ;
361
+
362
+ $animate . enter ( svgElement , parent ) ;
363
+ $rootScope . $digest ( ) ;
364
+ expect ( capturedAnimation ) . toBeNull ( ) ;
365
+
366
+ $animate . leave ( svgElement , parent ) ;
367
+ $rootScope . $digest ( ) ;
368
+ expect ( capturedAnimation ) . toBeNull ( ) ;
369
+
370
+ animationsAllowed = true ;
371
+
372
+ $animate . enter ( svgElement , parent ) ;
373
+ $rootScope . $digest ( ) ;
374
+ expect ( capturedAnimation ) . not . toBeNull ( ) ;
375
+
376
+ capturedAnimation = null ;
377
+
378
+ $animate . leave ( svgElement , parent ) ;
379
+ $rootScope . $digest ( ) ;
380
+ expect ( capturedAnimation ) . not . toBeNull ( ) ;
381
+ } ) ;
382
+ }
383
+ ) ;
384
+
385
+ it ( 'should pass the DOM element, event name and options to the filter function' , function ( ) {
386
+ var filterFn = jasmine . createSpy ( 'filterFn' ) ;
387
+ var options = { } ;
388
+
389
+ module ( function ( $animateProvider ) {
390
+ $animateProvider . customFilter ( filterFn ) ;
391
+ } ) ;
392
+
393
+ inject ( function ( $animate , $rootScope ) {
394
+ $animate . enter ( element , parent , null , options ) ;
395
+ expect ( filterFn ) . toHaveBeenCalledOnceWith ( element [ 0 ] , 'enter' , options ) ;
396
+
397
+ filterFn . calls . reset ( ) ;
398
+
399
+ $animate . leave ( element ) ;
400
+ expect ( filterFn ) . toHaveBeenCalledOnceWith ( element [ 0 ] , 'leave' , jasmine . any ( Object ) ) ;
401
+ } ) ;
402
+ } ) ;
403
+
404
+ it ( 'should complete the DOM operation even if filtered out' , function ( ) {
405
+ module ( function ( $animateProvider ) {
406
+ $animateProvider . customFilter ( function ( ) { return false ; } ) ;
407
+ } ) ;
408
+
409
+ inject ( function ( $animate , $rootScope ) {
410
+ expect ( element . parent ( ) [ 0 ] ) . toBeUndefined ( ) ;
411
+
412
+ $animate . enter ( element , parent ) ;
413
+ $rootScope . $digest ( ) ;
414
+
415
+ expect ( capturedAnimation ) . toBeNull ( ) ;
416
+ expect ( element . parent ( ) [ 0 ] ) . toBe ( parent [ 0 ] ) ;
417
+
418
+ $animate . leave ( element ) ;
419
+ $rootScope . $digest ( ) ;
420
+
421
+ expect ( capturedAnimation ) . toBeNull ( ) ;
422
+ expect ( element . parent ( ) [ 0 ] ) . toBeUndefined ( ) ;
423
+ } ) ;
424
+ } ) ;
425
+ } ) ;
426
+
298
427
describe ( 'enabled()' , function ( ) {
299
428
it ( 'should work for all animations' , inject ( function ( $animate ) {
300
429
0 commit comments