X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fdata.js;h=d21ec329fdb23ab87a51fe9a953f505f5fc48d88;hb=b996026e383eae34dd52824dda5bbe029e2eda51;hp=6b79da2d53f8cc39cf9d615ba3686740c1aaa474;hpb=991d039b62f5dfcb9e3d99fe28212a6874e8f5c7;p=jquery.git diff --git a/test/unit/data.js b/test/unit/data.js index 6b79da2..d21ec32 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -1,15 +1,46 @@ module("data"); +test("expando", function(){ + expect(7); + + 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" ); + + jQuery.data(obj, 'test'); + equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" ); + + jQuery.data(obj, "foo", "bar"); + equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" ); + + var id = obj[jQuery.expando]; + equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache" ); + + equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly" ); +}); + test("jQuery.data", function() { - expect(5); + expect(6); var div = jQuery("#foo")[0]; equals( 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" ); + + var data = jQuery.data(div); + same( data, { "test": "success" }, "Return complete data set" ); + jQuery.data(div, "test", "overwritten"); equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" ); + jQuery.data(div, "test", undefined); equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed"); + jQuery.data(div, "test", null); ok( jQuery.data(div, "test") === null, "Check for null data"); }); @@ -19,7 +50,7 @@ test(".data()", function() { var div = jQuery("#foo"); div.data("test", "success"); - isObj( div.data(), {test: "success"}, "data() get the entire data object" ) + same( div.data(), {test: "success"}, "data() get the entire data object" ) }) test(".data(String) and .data(String, Object)", function() {