X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fdata.js;h=c6ef843a12bdce2afc474e7b131479a2dff2ef44;hb=12c0e1a692aa045e9d3cf166a41748d7f5fe31cc;hp=28e19a3e20c2b9b4858b0204b0b664d2d9cc2786;hpb=8e59a99e0ade75dec434f246f52e8b3f7393f359;p=jquery.git diff --git a/test/unit/data.js b/test/unit/data.js index 28e19a3..c6ef843 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -180,15 +180,28 @@ 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"); 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); @@ -301,6 +314,8 @@ test("data-* attributes", function() { div.data("attr", "internal").attr("data-attr", "external"); equals( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" ); + div.remove(); + child.appendTo('#main'); equals( child.data("myobj"), "old data", "Value accessed from data-* attribute"); @@ -312,6 +327,8 @@ test("data-* attributes", function() { var obj = child.data(), obj2 = dummy.data(), check = [ "myobj", "ignored", "other" ], num = 0, num2 = 0; + dummy.remove(); + for ( var i = 0, l = check.length; i < l; i++ ) { ok( obj[ check[i] ], "Make sure data- property exists when calling data-." ); ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." ); @@ -321,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"); @@ -457,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