From 35b2b94979ed3419e50b72ab3b84307269fa25e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski?= Date: Thu, 24 Oct 2013 19:45:42 +0200 Subject: [PATCH] Add tests for class manipulation on jQuery object containing more than one element. Close gh-1404. --- test/unit/attributes.js | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 029c358c3..08e1dc2dc 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1357,6 +1357,49 @@ test( "addClass, removeClass, hasClass", function() { ok( jq.hasClass("class4") === false, "Check the class has been properly removed" ); }); +test( "addClass, removeClass, hasClass on many elements", function() { + expect( 19 ); + + var elem = jQuery( "

p0

p1

p2

" ); + + elem.addClass( "hi" ); + equal( elem[ 0 ].className, "hi", "Check single added class" ); + equal( elem[ 1 ].className, "hi", "Check single added class" ); + equal( elem[ 2 ].className, "hi", "Check single added class" ); + + elem.addClass( "foo bar" ); + equal( elem[ 0 ].className, "hi foo bar", "Check more added classes" ); + equal( elem[ 1 ].className, "hi foo bar", "Check more added classes" ); + equal( elem[ 2 ].className, "hi foo bar", "Check more added classes" ); + + elem.removeClass(); + equal( elem[ 0 ].className, "", "Remove all classes" ); + equal( elem[ 1 ].className, "", "Remove all classes" ); + equal( elem[ 2 ].className, "", "Remove all classes" ); + + elem.addClass( "hi foo bar" ); + elem.removeClass( "foo" ); + equal( elem[ 0 ].className, "hi bar", "Check removal of one class" ); + equal( elem[ 1 ].className, "hi bar", "Check removal of one class" ); + equal( elem[ 2 ].className, "hi bar", "Check removal of one class" ); + + ok( elem.hasClass( "hi" ), "Check has1" ); + ok( elem.hasClass( "bar" ), "Check has2" ); + + ok( jQuery( "

p0

p1

p2

" ).hasClass( "hi" ), + "Did find a class in the first element" ); + ok( jQuery( "

p0

p1

p2

" ).hasClass( "hi" ), + "Did find a class in the second element" ); + ok( jQuery( "

p0

p1

p2

" ).hasClass( "hi" ), + "Did find a class in the last element" ); + + ok( jQuery( "

p0

p1

p2

" ).hasClass( "hi" ), + "Did find a class when present in all elements" ); + + ok( !jQuery( "

p0

p1

p2

" ).hasClass( "hi" ), + "Did not find a class when not present" ); +}); + test( "contents().hasClass() returns correct values", function() { expect( 2 ); -- 2.39.5