@@ -914,6 +914,20 @@ describe('jqLite', function() {
914
914
} ) ;
915
915
916
916
917
+ it ( 'should only get/set the attribute once when multiple classes added' , function ( ) {
918
+ var fakeElement = {
919
+ nodeType : 1 ,
920
+ setAttribute : jasmine . createSpy ( ) ,
921
+ getAttribute : jasmine . createSpy ( ) . and . returnValue ( '' )
922
+ } ;
923
+ var jqA = jqLite ( fakeElement ) ;
924
+
925
+ jqA . addClass ( 'foo bar baz' ) ;
926
+ expect ( fakeElement . getAttribute ) . toHaveBeenCalledOnceWith ( 'class' ) ;
927
+ expect ( fakeElement . setAttribute ) . toHaveBeenCalledOnceWith ( 'class' , 'foo bar baz' ) ;
928
+ } ) ;
929
+
930
+
917
931
it ( 'should not add duplicate classes' , function ( ) {
918
932
var jqA = jqLite ( a ) ;
919
933
expect ( a . className ) . toBe ( '' ) ;
@@ -1031,6 +1045,20 @@ describe('jqLite', function() {
1031
1045
jqA . removeClass ( 'foo baz noexistent' ) ;
1032
1046
expect ( a . className ) . toBe ( 'bar' ) ;
1033
1047
} ) ;
1048
+
1049
+
1050
+ it ( 'should get/set the attribute once when removing multiple classes' , function ( ) {
1051
+ var fakeElement = {
1052
+ nodeType : 1 ,
1053
+ setAttribute : jasmine . createSpy ( ) ,
1054
+ getAttribute : jasmine . createSpy ( ) . and . returnValue ( 'foo bar baz' )
1055
+ } ;
1056
+ var jqA = jqLite ( fakeElement ) ;
1057
+
1058
+ jqA . removeClass ( 'foo baz noexistent' ) ;
1059
+ expect ( fakeElement . getAttribute ) . toHaveBeenCalledOnceWith ( 'class' ) ;
1060
+ expect ( fakeElement . setAttribute ) . toHaveBeenCalledOnceWith ( 'class' , 'bar' ) ;
1061
+ } ) ;
1034
1062
} ) ;
1035
1063
} ) ;
1036
1064
0 commit comments