-test("$.data", function() {
- expect(3);
- var div = $("#foo")[0];
- ok( jQuery.data(div, "test") == undefined, "Check for no data exists" );
- jQuery.data(div, "test", "success");
- ok( jQuery.data(div, "test") == "success", "Check for added data" );
- jQuery.data(div, "test", "overwritten");
- ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" );
-});
-
-test(".data()", function() {
- expect(16);
- var div = $("#foo");
- ok( div.data("test") == undefined, "Check for no data exists" );
- div.data("test", "success");
- ok( div.data("test") == "success", "Check for added data" );
- div.data("test", "overwritten");
- ok( div.data("test") == "overwritten", "Check for overwritten data" );
-
- var hits = {test:0}, gets = {test:0};
-
- div
- .bind("setData",function(e,key,value){ hits[key] += value; })
- .bind("setData.foo",function(e,key,value){ hits[key] += value; })
- .bind("getData",function(e,key){ gets[key] += 1; })
- .bind("getData.foo",function(e,key){ gets[key] += 3; });
-
- div.data("test.foo", 2);
- ok( div.data("test") == "overwritten", "Check for original data" );
- ok( div.data("test.foo") == 2, "Check for namespaced data" );
- ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" );
- equals( hits.test, 2, "Check triggered setter functions" );
- equals( gets.test, 5, "Check triggered getter functions" );
-
- hits.test = 0;
- gets.test = 0;
-
- div.data("test", 1);
- ok( div.data("test") == 1, "Check for original data" );
- ok( div.data("test.foo") == 2, "Check for namespaced data" );
- ok( div.data("test.bar") == 1, "Check for unmatched namespace" );
- equals( hits.test, 1, "Check triggered setter functions" );
- equals( gets.test, 5, "Check triggered getter functions" );
-
- hits.test = 0;
- gets.test = 0;
-
- div
- .bind("getData",function(e,key){ return key + "root"; })
- .bind("getData.foo",function(e,key){ return key + "foo"; });
-
- ok( div.data("test") == "testroot", "Check for original data" );
- ok( div.data("test.foo") == "testfoo", "Check for namespaced data" );
- ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" );
-});
-
-test("$.removeData", function() {
- expect(1);
- var div = $("#foo")[0];
- jQuery.data(div, "test", "testing");
- jQuery.removeData(div, "test");
- ok( jQuery.data(div, "test") == undefined, "Check removal of data" );
-});
-
-test(".removeData()", function() {
- expect(6);
- var div = $("#foo");
- div.data("test", "testing");
- div.removeData("test");
- ok( div.data("test") == undefined, "Check removal of data" );
-
- div.data("test", "testing");
- div.data("test.foo", "testing2");
- div.removeData("test.bar");
- ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
- ok( div.data("test") == "testing", "Make sure data is intact" );
-
- div.removeData("test");
- ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
- ok( div.data("test") == undefined, "Make sure data is intact" );
-
- div.removeData("test.foo");
- ok( div.data("test.foo") == undefined, "Make sure data is intact" );
-});
-