data should not add expando unless actually adding data
[jquery.git] / test / unit / data.js
index 46e46ed..6a367f7 100644 (file)
@@ -1,31 +1,46 @@
 module("data");\r
 \r
 test("expando", function(){\r
-       expect(4);\r
+       expect(7);\r
        \r
        equals("expando" in jQuery, true, "jQuery is exposing the expando");\r
        \r
        var obj = {};\r
+       jQuery.data(obj);\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
+       jQuery.data(obj, true);\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
+       jQuery.data(obj, 'test');\r
+       equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );\r
+       \r
        jQuery.data(obj, "foo", "bar");\r
-\r
-       equals(jQuery.expando in obj, true, "jQuery.data added an expando to the object");      \r
+       equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" );\r
        \r
        var id = obj[jQuery.expando];\r
-       equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache");\r
+       equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache" );\r
        \r
-       equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly");\r
+       equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly" );\r
 });\r
 \r
 test("jQuery.data", function() {\r
-       expect(5);\r
+       expect(6);\r
        var div = jQuery("#foo")[0];\r
        equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );\r
+       \r
        jQuery.data(div, "test", "success");\r
        equals( jQuery.data(div, "test"), "success", "Check for added data" );\r
+       \r
+       var data = jQuery.data(div, true);\r
+       same( data, { "test": "success" }, "Return complete data set" );\r
+       \r
        jQuery.data(div, "test", "overwritten");\r
        equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );\r
+       \r
        jQuery.data(div, "test", undefined);\r
        equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");\r
+       \r
        jQuery.data(div, "test", null);\r
        ok( jQuery.data(div, "test") === null, "Check for null data");\r
 });\r