@@ -28,6 +28,27 @@ describe('ngAnimate integration tests', function() {
28
28
describe ( 'CSS animations' , function ( ) {
29
29
if ( ! browserSupportsCssAnimations ( ) ) return ;
30
30
31
+ it ( "should only create a single copy of the provided animation options" ,
32
+ inject ( function ( $rootScope , $rootElement , $animate ) {
33
+
34
+ ss . addRule ( '.animate-me' , 'transition:2s linear all;' ) ;
35
+
36
+ var element = jqLite ( '<div class="animate-me"></div>' ) ;
37
+ html ( element ) ;
38
+
39
+ var myOptions = { to : { 'color' : 'red' } } ;
40
+
41
+ var spy = spyOn ( window , 'copy' ) ;
42
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
43
+
44
+ var animation = $animate . leave ( element , myOptions ) ;
45
+ $rootScope . $digest ( ) ;
46
+ $animate . flush ( ) ;
47
+
48
+ expect ( spy ) . toHaveBeenCalledOnce ( ) ;
49
+ dealoc ( element ) ;
50
+ } ) ) ;
51
+
31
52
they ( 'should render an $prop animation' ,
32
53
[ 'enter' , 'leave' , 'move' , 'addClass' , 'removeClass' , 'setClass' ] , function ( event ) {
33
54
@@ -637,50 +658,77 @@ describe('ngAnimate integration tests', function() {
637
658
}
638
659
} ) ;
639
660
} ) ;
661
+ } ) ;
640
662
641
- it ( "should not alter the provided options values in anyway throughout the animation" , function ( ) {
642
- var animationSpy = jasmine . createSpy ( ) ;
643
- module ( function ( $animateProvider ) {
644
- $animateProvider . register ( '.this-animation' , function ( ) {
645
- return {
646
- enter : function ( element , done ) {
647
- animationSpy ( ) ;
648
- done ( ) ;
649
- }
650
- } ;
651
- } ) ;
663
+ it ( "should not alter the provided options values in anyway throughout the animation" , function ( ) {
664
+ var animationSpy = jasmine . createSpy ( ) ;
665
+ module ( function ( $animateProvider ) {
666
+ $animateProvider . register ( '.this-animation' , function ( ) {
667
+ return {
668
+ enter : function ( element , done ) {
669
+ animationSpy ( ) ;
670
+ done ( ) ;
671
+ }
672
+ } ;
652
673
} ) ;
674
+ } ) ;
653
675
654
- inject ( function ( $animate , $rootScope , $compile ) {
655
- element = jqLite ( '<div class="parent-man"></div>' ) ;
656
- var child = jqLite ( '<div class="child-man one"></div>' ) ;
676
+ inject ( function ( $animate , $rootScope , $compile ) {
677
+ element = jqLite ( '<div class="parent-man"></div>' ) ;
678
+ var child = jqLite ( '<div class="child-man one"></div>' ) ;
657
679
658
- var initialOptions = {
659
- from : { height : '50px' } ,
660
- to : { width : '100px' } ,
661
- addClass : 'one' ,
662
- removeClass : 'two'
663
- } ;
680
+ var initialOptions = {
681
+ from : { height : '50px' } ,
682
+ to : { width : '100px' } ,
683
+ addClass : 'one' ,
684
+ removeClass : 'two'
685
+ } ;
664
686
665
- var copiedOptions = copy ( initialOptions ) ;
666
- expect ( copiedOptions ) . toEqual ( initialOptions ) ;
687
+ var copiedOptions = copy ( initialOptions ) ;
688
+ expect ( copiedOptions ) . toEqual ( initialOptions ) ;
667
689
668
- html ( element ) ;
669
- $compile ( element ) ( $rootScope ) ;
690
+ html ( element ) ;
691
+ $compile ( element ) ( $rootScope ) ;
670
692
671
- $animate . enter ( child , element , null , copiedOptions ) ;
672
- $rootScope . $digest ( ) ;
673
- expect ( copiedOptions ) . toEqual ( initialOptions ) ;
693
+ $animate . enter ( child , element , null , copiedOptions ) ;
694
+ $rootScope . $digest ( ) ;
695
+ expect ( copiedOptions ) . toEqual ( initialOptions ) ;
674
696
675
- $animate . flush ( ) ;
676
- expect ( copiedOptions ) . toEqual ( initialOptions ) ;
697
+ $animate . flush ( ) ;
698
+ expect ( copiedOptions ) . toEqual ( initialOptions ) ;
677
699
678
- expect ( child ) . toHaveClass ( 'one' ) ;
679
- expect ( child ) . not . toHaveClass ( 'two' ) ;
700
+ expect ( child ) . toHaveClass ( 'one' ) ;
701
+ expect ( child ) . not . toHaveClass ( 'two' ) ;
680
702
681
- expect ( child . attr ( 'style' ) ) . toContain ( '100px' ) ;
682
- expect ( child . attr ( 'style' ) ) . toContain ( '50px' ) ;
683
- } ) ;
703
+ expect ( child . attr ( 'style' ) ) . toContain ( '100px' ) ;
704
+ expect ( child . attr ( 'style' ) ) . toContain ( '50px' ) ;
705
+ } ) ;
706
+ } ) ;
707
+
708
+ it ( 'should handle ng-if & ng-class with a class that is removed before its add animation has concluded' , function ( ) {
709
+ inject ( function ( $animate , $rootScope , $compile , $timeout , $$rAF ) {
710
+
711
+ ss . addRule ( '.animate-me' , 'transition: all 0.5s;' ) ;
712
+
713
+ element = jqLite ( '<section><div ng-if="true" class="animate-me" ng-class="{' +
714
+ 'red: red,' +
715
+ 'blue: blue' +
716
+ '}"></div></section>' ) ;
717
+
718
+ html ( element ) ;
719
+ $rootScope . blue = true ;
720
+ $rootScope . red = true ;
721
+ $compile ( element ) ( $rootScope ) ;
722
+ $rootScope . $digest ( ) ;
723
+
724
+ var child = element . find ( 'div' ) ;
725
+
726
+ // Trigger class removal before the add animation has been concluded
727
+ $rootScope . blue = false ;
728
+ $animate . closeAndFlush ( ) ;
729
+
730
+ expect ( child ) . toHaveClass ( 'red' ) ;
731
+ expect ( child ) . not . toHaveClass ( 'blue' ) ;
684
732
} ) ;
685
733
} ) ;
686
734
} ) ;
0 commit comments