aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2011-12-06 15:25:38 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-12-06 15:25:38 -0500
commit6c2a501de40a5f6b3ad382e2d309e5a10fce04d0 (patch)
treec72333c9a1d5d29acd4e3224ddf6d4e4e00db5fe /test/unit
parentd511613d748a92af04a3f07943f34f9baadc4153 (diff)
downloadjquery-6c2a501de40a5f6b3ad382e2d309e5a10fce04d0.tar.gz
jquery-6c2a501de40a5f6b3ad382e2d309e5a10fce04d0.zip
Fix #5571. Setters should treat `undefined` as a no-op and be chainable.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/attributes.js8
-rw-r--r--test/unit/data.js3
-rw-r--r--test/unit/dimensions.js18
-rw-r--r--test/unit/manipulation.js10
-rw-r--r--test/unit/offset.js12
-rw-r--r--test/unit/queue.js6
6 files changed, 43 insertions, 14 deletions
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 0bdea7f96..dbfa8c0c1 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -158,7 +158,7 @@ test("attr(Hash)", function() {
});
test("attr(String, Object)", function() {
- expect(78);
+ expect(81);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
@@ -353,6 +353,12 @@ test("attr(String, Object)", function() {
+ "</svg>").appendTo("body");
equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
$svg.remove();
+
+ // undefined values are chainable
+ jQuery("#name").attr("maxlength", "5").removeAttr("nonexisting");
+ equal( typeof jQuery("#name").attr("maxlength", undefined), "object", ".attr('attribute', undefined) is chainable (#5571)" );
+ equal( jQuery("#name").attr("maxlength", undefined).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (#5571)" );
+ equal( jQuery("#name").attr("nonexisting", undefined).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
});
test("attr(jquery_method)", function(){
diff --git a/test/unit/data.js b/test/unit/data.js
index 133793817..006e29e6a 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -222,8 +222,7 @@ test(".data(String) and .data(String, Object)", function() {
div.data("test", "overwritten");
equal( div.data("test"), "overwritten", "Check for overwritten data" );
- div.data("test", undefined);
- equal( div.data("test"), "overwritten", "Check that data wasn't removed");
+ equal( div.data("test", undefined).data("test"), "overwritten", "Check that .data('key',undefined) does nothing but is chainable (#5571)");
div.data("test", null);
ok( div.data("test") === null, "Check for null data");
diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js
index 117247822..222459f51 100644
--- a/test/unit/dimensions.js
+++ b/test/unit/dimensions.js
@@ -41,11 +41,16 @@ test("width()", function() {
testWidth( pass );
});
-test("width() with function", function() {
+test("width(undefined)", function() {
+ expect(1);
+ equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)");
+});
+
+test("width(Function)", function() {
testWidth( fn );
});
-test("width() with function args", function() {
+test("width(Function(args))", function() {
expect( 2 );
var $div = jQuery("#nothiddendiv");
@@ -90,11 +95,16 @@ test("height()", function() {
testHeight( pass );
});
-test("height() with function", function() {
+test("height(undefined)", function() {
+ expect(1);
+ equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)");
+});
+
+test("height(Function)", function() {
testHeight( fn );
});
-test("height() with function args", function() {
+test("height(Function(args))", function() {
expect( 2 );
var $div = jQuery("#nothiddendiv");
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index f690b721d..44bb9110c 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -16,6 +16,11 @@ test("text()", function() {
notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724).");
});
+test("text(undefined)", function() {
+ expect(1);
+ equal( jQuery("#foo").text("<div").text(undefined)[0].innerHTML, "&lt;div", ".text(undefined) is chainable (#5571)" );
+});
+
var testText = function(valueObj) {
expect(4);
var val = valueObj("<div><b>Hello</b> cruel world!</div>");
@@ -1207,6 +1212,11 @@ test("clone() on XML nodes", function() {
});
}
+test("html(undefined)", function() {
+ expect(1);
+ equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
+});
+
var testHtml = function(valueObj) {
expect(34);
diff --git a/test/unit/offset.js b/test/unit/offset.js
index a37130653..466e65006 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -342,7 +342,7 @@ testoffset("table", function( jQuery ) {
});
testoffset("scroll", function( jQuery, win ) {
- expect(22);
+ expect(24);
var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;
@@ -362,8 +362,9 @@ testoffset("scroll", function( jQuery, win ) {
equal( jQuery("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equal( jQuery("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
- // equal( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" );
- // equal( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" );
+ // scroll method chaining
+ equal( jQuery("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
+ equal( jQuery("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
win.name = "test";
@@ -405,11 +406,12 @@ testoffset("body", function( jQuery ) {
equal( jQuery("body").offset().left, 1, "jQuery('#body').offset().left" );
});
-test("Chaining offset(coords) returns jQuery object", function() {
- expect(2);
+test("chaining", function() {
+ expect(3);
var coords = { top: 1, left: 1 };
equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
+ equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
});
test("offsetParent", function(){
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 40523e7f9..701956050 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,7 +1,7 @@
module("queue", { teardown: moduleTeardown });
test("queue() with other types",function() {
- expect(11);
+ expect(12);
var counter = 0;
stop();
@@ -36,6 +36,8 @@ test("queue() with other types",function() {
equal( $div.queue("foo").length, 4, "Testing queue length" );
+ equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
+
$div.dequeue("foo");
equal( counter, 3, "Testing previous call to dequeue" );
@@ -289,4 +291,4 @@ test("promise()", function() {
jQuery.each( objects, function() {
this.dequeue();
});
-}); \ No newline at end of file
+});