X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=412ba39c354bde17d7f03d3c9dde1abac9e12247;hb=291f071eff51bc0653aaf3dcfd777cc57437ebdf;hp=7b0aad4ed2cc085c4fc81d3e3c694adade47cebf;hpb=1faed11e3c0752981d8b01e1272fb3a72272f966;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 7b0aad4..412ba39 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1397,6 +1397,52 @@ test("$.data", function() { ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" ); }); +test(".data()", function() { + expect(16); + var div = $("#foo"); + ok( div.data("test") == undefined, "Check for no data exists" ); + div.data("test", "success"); + ok( div.data("test") == "success", "Check for added data" ); + div.data("test", "overwritten"); + ok( div.data("test") == "overwritten", "Check for overwritten data" ); + + var hits = {test:0}, gets = {test:0}; + + div + .bind("setData",function(e,key,value){ hits[key] += value; }) + .bind("setData.foo",function(e,key,value){ hits[key] += value; }) + .bind("getData",function(e,key){ gets[key] += 1; }) + .bind("getData.foo",function(e,key){ gets[key] += 3; }); + + div.data("test.foo", 2); + ok( div.data("test") == "overwritten", "Check for original data" ); + ok( div.data("test.foo") == 2, "Check for namespaced data" ); + ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" ); + equals( hits.test, 2, "Check triggered setter functions" ); + equals( gets.test, 5, "Check triggered getter functions" ); + + hits.test = 0; + gets.test = 0; + + div.data("test", 1); + ok( div.data("test") == 1, "Check for original data" ); + ok( div.data("test.foo") == 2, "Check for namespaced data" ); + ok( div.data("test.bar") == 1, "Check for unmatched namespace" ); + equals( hits.test, 1, "Check triggered setter functions" ); + equals( gets.test, 5, "Check triggered getter functions" ); + + hits.test = 0; + gets.test = 0; + + div + .bind("getData",function(e,key){ return key + "root"; }) + .bind("getData.foo",function(e,key){ return key + "foo"; }); + + ok( div.data("test") == "testroot", "Check for original data" ); + ok( div.data("test.foo") == "testfoo", "Check for namespaced data" ); + ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" ); +}); + test("$.removeData", function() { expect(1); var div = $("#foo")[0]; @@ -1405,6 +1451,27 @@ test("$.removeData", function() { ok( jQuery.data(div, "test") == undefined, "Check removal of data" ); }); +test(".removeData()", function() { + expect(6); + var div = $("#foo"); + div.data("test", "testing"); + div.removeData("test"); + ok( div.data("test") == undefined, "Check removal of data" ); + + div.data("test", "testing"); + div.data("test.foo", "testing2"); + div.removeData("test.bar"); + ok( div.data("test.foo") == "testing2", "Make sure data is intact" ); + ok( div.data("test") == "testing", "Make sure data is intact" ); + + div.removeData("test"); + ok( div.data("test.foo") == "testing2", "Make sure data is intact" ); + ok( div.data("test") == undefined, "Make sure data is intact" ); + + div.removeData("test.foo"); + ok( div.data("test.foo") == undefined, "Make sure data is intact" ); +}); + test("remove()", function() { expect(6); $("#ap").children().remove(); @@ -1494,3 +1561,30 @@ test("contents()", function() { equals( c.length, 1, "Check node,textnode,comment contents is just one" ); equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); }); + +test("makeArray(#2619)", function(){ + expect(11); + + equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); + + equals( (function(){ return $.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); + + equals( $.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); + + equals( $.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" ); + + equals( $.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); + + equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); + + equals( typeof $.makeArray( true )[0], "boolean", "Pass makeArray a boolean" ); + + equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" ); + + equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); + + equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodeson array" ); + + //function (tricky, they have length) + equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); +}); \ No newline at end of file