@@ -345,6 +345,7 @@ describe("ngAnimate", function() {
345
345
346
346
$animate . enabled ( true ) ;
347
347
348
+ element . addClass ( 'ng-hide' ) ;
348
349
$animate . removeClass ( element , 'ng-hide' ) ;
349
350
expect ( element . text ( ) ) . toBe ( 'memento' ) ;
350
351
} ) ) ;
@@ -616,7 +617,7 @@ describe("ngAnimate", function() {
616
617
ss . addRule ( '.ng-hide-add' , style ) ;
617
618
ss . addRule ( '.ng-hide-remove' , style ) ;
618
619
619
- element = $compile ( html ( '<div>1</div>' ) ) ( $rootScope ) ;
620
+ element = $compile ( html ( '<div class="ng-hide" >1</div>' ) ) ( $rootScope ) ;
620
621
element . addClass ( 'custom' ) ;
621
622
622
623
$animate . removeClass ( element , 'ng-hide' ) ;
@@ -627,6 +628,7 @@ describe("ngAnimate", function() {
627
628
expect ( element . hasClass ( 'ng-hide-remove-active' ) ) . toBe ( true ) ;
628
629
}
629
630
631
+ element . removeClass ( 'ng-hide' ) ;
630
632
$animate . addClass ( element , 'ng-hide' ) ;
631
633
expect ( element . hasClass ( 'ng-hide-remove' ) ) . toBe ( false ) ; //added right away
632
634
@@ -1052,21 +1054,59 @@ describe("ngAnimate", function() {
1052
1054
} ) ;
1053
1055
1054
1056
describe ( "addClass / removeClass" , function ( ) {
1057
+ var captured ;
1055
1058
beforeEach ( function ( ) {
1056
1059
module ( function ( $animateProvider , $provide ) {
1057
1060
$animateProvider . register ( '.klassy' , function ( $timeout ) {
1058
1061
return {
1059
1062
addClass : function ( element , className , done ) {
1063
+ captured = 'addClass-' + className ;
1060
1064
$timeout ( done , 500 , false ) ;
1061
1065
} ,
1062
1066
removeClass : function ( element , className , done ) {
1067
+ captured = 'removeClass-' + className ;
1063
1068
$timeout ( done , 3000 , false ) ;
1064
1069
}
1065
1070
}
1066
1071
} ) ;
1067
1072
} ) ;
1068
1073
} ) ;
1069
1074
1075
+ it ( "should not perform an animation, and the followup DOM operation, if the class is " +
1076
+ "already present during addClass or not present during removeClass on the element" ,
1077
+ inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout ) {
1078
+
1079
+ var element = jqLite ( '<div class="klassy"></div>' ) ;
1080
+ $rootElement . append ( element ) ;
1081
+ body . append ( $rootElement ) ;
1082
+
1083
+ //skipped animations
1084
+ captured = 'none' ;
1085
+ $animate . removeClass ( element , 'some-class' ) ;
1086
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
1087
+ expect ( captured ) . toBe ( 'none' ) ;
1088
+
1089
+ element . addClass ( 'some-class' ) ;
1090
+
1091
+ captured = 'nothing' ;
1092
+ $animate . addClass ( element , 'some-class' ) ;
1093
+ expect ( captured ) . toBe ( 'nothing' ) ;
1094
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
1095
+
1096
+ //actual animations
1097
+ captured = 'none' ;
1098
+ $animate . removeClass ( element , 'some-class' ) ;
1099
+ $timeout . flush ( ) ;
1100
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
1101
+ expect ( captured ) . toBe ( 'removeClass-some-class' ) ;
1102
+
1103
+ captured = 'nothing' ;
1104
+ $animate . addClass ( element , 'some-class' ) ;
1105
+ $timeout . flush ( ) ;
1106
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
1107
+ expect ( captured ) . toBe ( 'addClass-some-class' ) ;
1108
+ } ) ) ;
1109
+
1070
1110
it ( "should add and remove CSS classes after an animation even if no animation is present" ,
1071
1111
inject ( function ( $animate , $rootScope , $sniffer , $rootElement ) {
1072
1112
0 commit comments