X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fdata.js;h=d21ec329fdb23ab87a51fe9a953f505f5fc48d88;hb=ac00fe5bbb2a95fdb747f76fd9dd7c58ba6a531c;hp=46e46ed5a79326c340b03ca90e208f9f4bd79434;hpb=a2731202917f8e90cad94ee574241d1626dc7fb6;p=jquery.git diff --git a/test/unit/data.js b/test/unit/data.js index 46e46ed..d21ec32 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -1,31 +1,46 @@ module("data"); test("expando", function(){ - expect(4); + 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"); + 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( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache" ); - equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly"); + 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"); }); @@ -35,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() {