X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=80e92e6bec958a4056c64087ab807f78956b3fe7;hb=77da94552e94925e990d058ed81419d0835747ce;hp=7b0aad4ed2cc085c4fc81d3e3c694adade47cebf;hpb=1faed11e3c0752981d8b01e1272fb3a72272f966;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 7b0aad4..80e92e6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1397,6 +1397,36 @@ test("$.data", function() { ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" ); }); +test(".data()", function() { + expect(11); + 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 = 0; + + div + .bind("set-test",function(){ hits += 1; }) + .bind("set-test.foo",function(){ hits += 2; }) + + div.data("test.foo", "foodata"); + ok( div.data("test") == "overwritten", "Check for original data" ); + ok( div.data("test.foo") == "foodata", "Check for namespaced data" ); + ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" ); + ok( hits == 2, "Check triggered functions" ); + + hits = 0; + + div.data("test", "overwritten2"); + ok( div.data("test") == "overwritten2", "Check for original data" ); + ok( div.data("test.foo") == "foodata", "Check for namespaced data" ); + ok( div.data("test.bar") == "overwritten2", "Check for unmatched namespace" ); + ok( hits == 1, "Check triggered functions" ); +}); + test("$.removeData", function() { expect(1); var div = $("#foo")[0]; @@ -1405,6 +1435,27 @@ test("$.removeData", function() { 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" ); +}); + test("remove()", function() { expect(6); $("#ap").children().remove();