Make sure that undefined is always returned for undefined data properties. Fixes #6166.
This commit is contained in:
parent
7f5179b654
commit
9e06903a99
|
@ -25,7 +25,7 @@ jQuery.extend({
|
||||||
var id = elem[ expando ], cache = jQuery.cache, thisCache;
|
var id = elem[ expando ], cache = jQuery.cache, thisCache;
|
||||||
|
|
||||||
if ( !id && typeof name === "string" && data === undefined ) {
|
if ( !id && typeof name === "string" && data === undefined ) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute a unique ID for the element
|
// Compute a unique ID for the element
|
||||||
|
|
|
@ -24,13 +24,16 @@ test("expando", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.data", function() {
|
test("jQuery.data", function() {
|
||||||
expect(8);
|
expect(9);
|
||||||
var div = jQuery("#foo")[0];
|
var div = document.createElement("div");
|
||||||
equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
|
|
||||||
|
ok( jQuery.data(div, "test") === undefined, "Check for no data exists" );
|
||||||
|
|
||||||
jQuery.data(div, "test", "success");
|
jQuery.data(div, "test", "success");
|
||||||
equals( jQuery.data(div, "test"), "success", "Check for added data" );
|
equals( jQuery.data(div, "test"), "success", "Check for added data" );
|
||||||
|
|
||||||
|
ok( jQuery.data(div, "notexist") === undefined, "Check for no data exists" );
|
||||||
|
|
||||||
var data = jQuery.data(div);
|
var data = jQuery.data(div);
|
||||||
same( data, { "test": "success" }, "Return complete data set" );
|
same( data, { "test": "success" }, "Return complete data set" );
|
||||||
|
|
||||||
|
@ -57,18 +60,25 @@ test(".data()", function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
test(".data(String) and .data(String, Object)", function() {
|
test(".data(String) and .data(String, Object)", function() {
|
||||||
expect(22);
|
expect(23);
|
||||||
var div = jQuery("#foo");
|
var div = jQuery("<div/>");
|
||||||
equals( div.data("test"), undefined, "Check for no data exists" );
|
|
||||||
|
ok( div.data("test") === undefined, "Check for no data exists" );
|
||||||
|
|
||||||
div.data("test", "success");
|
div.data("test", "success");
|
||||||
equals( div.data("test"), "success", "Check for added data" );
|
equals( div.data("test"), "success", "Check for added data" );
|
||||||
|
|
||||||
div.data("test", "overwritten");
|
div.data("test", "overwritten");
|
||||||
equals( div.data("test"), "overwritten", "Check for overwritten data" );
|
equals( div.data("test"), "overwritten", "Check for overwritten data" );
|
||||||
|
|
||||||
div.data("test", undefined);
|
div.data("test", undefined);
|
||||||
equals( div.data("test"), "overwritten", "Check that data wasn't removed");
|
equals( div.data("test"), "overwritten", "Check that data wasn't removed");
|
||||||
|
|
||||||
div.data("test", null);
|
div.data("test", null);
|
||||||
ok( div.data("test") === null, "Check for null data");
|
ok( div.data("test") === null, "Check for null data");
|
||||||
|
|
||||||
|
ok( div.data("notexist") === undefined, "Check for no data exists" );
|
||||||
|
|
||||||
div.data("test", "overwritten");
|
div.data("test", "overwritten");
|
||||||
var hits = {test:0}, gets = {test:0};
|
var hits = {test:0}, gets = {test:0};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue