A follow-up to [6578] (which stopped adding expandos to elements that didn't have...
[jquery.git] / test / unit / data.js
index 6b79da2..8401fce 100644 (file)
@@ -1,15 +1,46 @@
 module("data");\r
 \r
+test("expando", function(){\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
+       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
+       \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);\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