3 test("expando", function(){
6 equals("expando" in jQuery, true, "jQuery is exposing the expando");
10 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
12 jQuery.data(obj, true);
13 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
15 jQuery.data(obj, 'test');
16 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
18 jQuery.data(obj, "foo", "bar");
19 equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" );
21 var id = obj[jQuery.expando];
22 equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache" );
24 equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly" );
27 test("jQuery.data", function() {
29 var div = jQuery("#foo")[0];
30 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
32 jQuery.data(div, "test", "success");
33 equals( jQuery.data(div, "test"), "success", "Check for added data" );
35 var data = jQuery.data(div);
36 same( data, { "test": "success" }, "Return complete data set" );
38 jQuery.data(div, "test", "overwritten");
39 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
41 jQuery.data(div, "test", undefined);
42 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
44 jQuery.data(div, "test", null);
45 ok( jQuery.data(div, "test") === null, "Check for null data");
48 test(".data()", function() {
51 var div = jQuery("#foo");
52 div.data("test", "success");
53 same( div.data(), {test: "success"}, "data() get the entire data object" )
56 test(".data(String) and .data(String, Object)", function() {
58 var div = jQuery("#foo");
59 equals( div.data("test"), undefined, "Check for no data exists" );
60 div.data("test", "success");
61 equals( div.data("test"), "success", "Check for added data" );
62 div.data("test", "overwritten");
63 equals( div.data("test"), "overwritten", "Check for overwritten data" );
64 div.data("test", undefined);
65 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
66 div.data("test", null);
67 ok( div.data("test") === null, "Check for null data");
69 div.data("test", "overwritten");
70 var hits = {test:0}, gets = {test:0};
73 .bind("setData",function(e,key,value){ hits[key] += value; })
74 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
75 .bind("getData",function(e,key){ gets[key] += 1; })
76 .bind("getData.foo",function(e,key){ gets[key] += 3; });
78 div.data("test.foo", 2);
79 equals( div.data("test"), "overwritten", "Check for original data" );
80 equals( div.data("test.foo"), 2, "Check for namespaced data" );
81 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
82 equals( hits.test, 2, "Check triggered setter functions" );
83 equals( gets.test, 5, "Check triggered getter functions" );
89 equals( div.data("test"), 1, "Check for original data" );
90 equals( div.data("test.foo"), 2, "Check for namespaced data" );
91 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
92 equals( hits.test, 1, "Check triggered setter functions" );
93 equals( gets.test, 5, "Check triggered getter functions" );
99 .bind("getData",function(e,key){ return key + "root"; })
100 .bind("getData.foo",function(e,key){ return key + "foo"; });
102 equals( div.data("test"), "testroot", "Check for original data" );
103 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
104 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
107 var $elem = jQuery({});
108 equals( $elem.data('nothing'), undefined, "Non-existent data returns undefined");
109 equals( $elem.data('null',null).data('null'), null, "null's are preserved");
110 equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved");
111 equals( $elem.data('false',false).data('false'), false, "false's are preserved");
117 test("jQuery.removeData", function() {
119 var div = jQuery("#foo")[0];
120 jQuery.data(div, "test", "testing");
121 jQuery.removeData(div, "test");
122 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
125 test(".removeData()", function() {
127 var div = jQuery("#foo");
128 div.data("test", "testing");
129 div.removeData("test");
130 equals( div.data("test"), undefined, "Check removal of data" );
132 div.data("test", "testing");
133 div.data("test.foo", "testing2");
134 div.removeData("test.bar");
135 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
136 equals( div.data("test"), "testing", "Make sure data is intact" );
138 div.removeData("test");
139 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
140 equals( div.data("test"), undefined, "Make sure data is intact" );
142 div.removeData("test.foo");
143 equals( div.data("test.foo"), undefined, "Make sure data is intact" );