var div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success");
- same( div.data(), {test: "success"}, "data() get the entire data object" );
+
+ var dataObj = div.data();
+
+ // TODO: Remove this hack which was introduced in 1.5.1
+ delete dataObj.toJSON;
+
+ same( dataObj, {test: "success"}, "data() get the entire data object" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
var nodiv = jQuery("#unfound");
equals( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" };
- deepEqual( jQuery(obj).data(), {}, "Retrieve data object from a wrapped JS object (#7524)" );
-})
+ jQuery(obj).data("foo", "baz");
+
+ dataObj = jQuery.extend(true, {}, jQuery(obj).data());
+
+ // TODO: Remove this hack which was introduced for 1.5.1
+ delete dataObj.toJSON;
+
+ deepEqual( dataObj, { foo: "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
+});
test(".data(String) and .data(String, Object)", function() {
expect(29);
div.removeData("test.foo");
equals( div.data("test.foo"), undefined, "Make sure data is intact" );
-});
\ No newline at end of file
+});
+
+if (window.JSON && window.JSON.stringify) {
+ test("JSON serialization (#8108)", function () {
+ expect(1);
+
+ var obj = { foo: "bar" };
+ jQuery.data(obj, "hidden", true);
+
+ equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
+ });
+}
\ No newline at end of file