Skip to content
Permalink
Browse files

Fix #12411, .removeClass(undefined) is a chaining no-op. Close gh-913.

.removeClass() //removes all classes, as documented
.removeClass(window.nonExistentVariable) // removes nothing
  • Loading branch information...
matjae authored and dmethvin committed Aug 28, 2012
1 parent 23d125a commit 227c49a4596423a125bdcb1d25a2263e526360db
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/attributes.js
  2. +9 −0 test/unit/attributes.js
@@ -78,7 +78,7 @@ jQuery.fn.extend({
jQuery( this ).removeClass( value.call(this, j, this.className) );
});
}
if ( (value && typeof value === "string") || value === undefined ) {
if ( (value && typeof value === "string") || !arguments.length ) {
removes = ( value || "" ).split( core_rspace );

for ( i = 0, l = this.length; i < l; i++ ) {
@@ -1202,6 +1202,15 @@ test( "removeClass() removes duplicates", function() {
ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" );
});

test("removeClass(undefined) is a no-op", function() {
expect( 1 );

var $div = jQuery("<div class='base second'></div>");
$div.removeClass( undefined );

ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" );

This comment has been minimized.

Copy link
@Krinkle

Krinkle Oct 25, 2012

Member

Maybe additionally assert that the return value is strictEqual to $div? That way it doesn't just assert it being a no-op, but it also actually being chainable.

edit: Done in pull #1008.

});

var testToggleClass = function(valueObj) {
expect( 17 );

0 comments on commit 227c49a

Please sign in to comment.
You can’t perform that action at this time.