aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorColin Snover <github.com@zetafleet.com>2011-02-14 16:22:23 -0600
committerColin Snover <github.com@zetafleet.com>2011-02-14 16:22:23 -0600
commit2ed81708bdacfd4b97b77baef67ad8b75205dd20 (patch)
tree25a6f1dfbf0aa6d9703ada0c79853d76ec84f9d5 /test/unit
parent217a9919c3adcde198774301aa082e5be8a6489d (diff)
downloadjquery-2ed81708bdacfd4b97b77baef67ad8b75205dd20.tar.gz
jquery-2ed81708bdacfd4b97b77baef67ad8b75205dd20.zip
Hide metadata when serializing JS objects using JSON.stringify via a toJSON hack. Fixes #8108.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/data.js32
1 files changed, 29 insertions, 3 deletions
diff --git a/test/unit/data.js b/test/unit/data.js
index 455b923aa..c6ef843a1 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -180,7 +180,13 @@ test(".data()", function() {
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");
@@ -189,7 +195,10 @@ test(".data()", function() {
var obj = { foo: "bar" };
jQuery(obj).data("foo", "baz");
- var dataObj = jQuery.extend(true, {}, jQuery(obj).data());
+ 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)" );
});
@@ -329,12 +338,18 @@ test("data-* attributes", function() {
num++;
}
+ // TODO: Remove this hack which was introduced for 1.5.1
+ num--;
+
equals( num, check.length, "Make sure that the right number of properties came through." );
for ( var prop in obj2 ) {
num2++;
}
+ // TODO: Remove this hack which was introduced for 1.5.1
+ num2--;
+
equals( num2, check.length, "Make sure that the right number of properties came through." );
child.attr("data-other", "newvalue");
@@ -465,4 +480,15 @@ test(".removeData()", function() {
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