git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make sure that undefined is always returned for undefined data properties. Fixes...
[jquery.git]
/
test
/
unit
/
data.js
diff --git
a/test/unit/data.js
b/test/unit/data.js
index
fd03c54
..
0d75bc4
100644
(file)
--- a/
test/unit/data.js
+++ b/
test/unit/data.js
@@
-1,20
+1,19
@@
module("data");
test("expando", function(){
module("data");
test("expando", function(){
- expect(7);
+ expect(6);
equals("expando" in jQuery, true, "jQuery is exposing the expando");
var obj = {};
jQuery.data(obj);
equals("expando" in jQuery, true, "jQuery is exposing the expando");
var obj = {};
jQuery.data(obj);
- equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
-
- jQuery.data(obj, true);
- equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
-
+ equals( jQuery.expando in obj, true, "jQuery.data adds an expando to the object" );
+
+ obj = {};
jQuery.data(obj, 'test');
equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
jQuery.data(obj, 'test');
equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
-
+
+ obj = {};
jQuery.data(obj, "foo", "bar");
equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" );
jQuery.data(obj, "foo", "bar");
equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" );
@@
-25,12
+24,15
@@
test("expando", function(){
});
test("jQuery.data", function() {
});
test("jQuery.data", function() {
- expect(8);
- var div = jQuery("#foo")[0];
- equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
+ expect(9);
+ var div = document.createElement("div");
+
+ ok( jQuery.data(div, "test") === undefined, "Check for no data exists" );
jQuery.data(div, "test", "success");
equals( jQuery.data(div, "test"), "success", "Check for added data" );
jQuery.data(div, "test", "success");
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);
same( data, { "test": "success" }, "Return complete data set" );
var data = jQuery.data(div);
same( data, { "test": "success" }, "Return complete data set" );
@@
-58,18
+60,25
@@
test(".data()", function() {
})
test(".data(String) and .data(String, Object)", function() {
})
test(".data(String) and .data(String, Object)", function() {
- expect(22);
- var div = jQuery("#foo");
- equals( div.data("test"), undefined, "Check for no data exists" );
+ expect(23);
+ var div = jQuery("<div/>");
+
+ ok( div.data("test") === undefined, "Check for no data exists" );
+
div.data("test", "success");
equals( div.data("test"), "success", "Check for added data" );
div.data("test", "success");
equals( div.data("test"), "success", "Check for added data" );
+
div.data("test", "overwritten");
equals( div.data("test"), "overwritten", "Check for overwritten data" );
div.data("test", "overwritten");
equals( div.data("test"), "overwritten", "Check for overwritten data" );
+
div.data("test", undefined);
equals( div.data("test"), "overwritten", "Check that data wasn't removed");
div.data("test", undefined);
equals( div.data("test"), "overwritten", "Check that data wasn't removed");
+
div.data("test", null);
ok( div.data("test") === null, "Check for null data");
div.data("test", null);
ok( div.data("test") === null, "Check for null data");
+ ok( div.data("notexist") === undefined, "Check for no data exists" );
+
div.data("test", "overwritten");
var hits = {test:0}, gets = {test:0};
div.data("test", "overwritten");
var hits = {test:0}, gets = {test:0};