X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fmanipulation.js;h=48050168435aa1cc842024a6ac04b5a4cd60cc94;hb=9fa9a570762c2b6dc6131b28b13547964d91be3e;hp=87af324d2a07bbe70e82948d213a50ab33c69179;hpb=9ce1d09a0a002eb147411166dee800335a60f4e4;p=jquery.git diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 87af324..4805016 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -680,7 +680,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { }); var testReplaceWith = function(val) { - expect(17); + expect(20); jQuery('#yahoo').replaceWith(val( 'buga' )); ok( jQuery("#replace")[0], 'Replace element with string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); @@ -748,6 +748,17 @@ var testReplaceWith = function(val) { //""); equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.'); jQuery('.replacewith').remove(); + + QUnit.reset(); + + jQuery("#main").append("
"); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("
") ); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("
") ); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); } test("replaceWith(String|Element|Array<Element>|jQuery)", function() { @@ -757,7 +768,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() { test("replaceWith(Function)", function() { testReplaceWith(functionReturningObj); - expect(18); + expect(21); var y = jQuery("#yahoo")[0]; @@ -803,7 +814,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() { }); test("clone()", function() { - expect(31); + expect(32); equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' ); var clone = jQuery('#yahoo').clone(); equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' ); @@ -861,6 +872,8 @@ test("clone()", function() { form.appendChild( div ); equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); + + equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" ); }); if (!isLocal) { @@ -899,7 +912,7 @@ var testHtml = function(valueObj) { equals( div.children().children().length, 1, "Make sure that a grandchild exists." ); var space = jQuery("
").html(valueObj(" "))[0].innerHTML; - ok( /^\s$|^ $/.test( space ), "Make sure entities are passed through correctly." ); + ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." ); equals( jQuery("
").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." ); jQuery("#main").html(valueObj("")); @@ -955,6 +968,17 @@ test("html(String)", function() { test("html(Function)", function() { testHtml(functionReturningObj); + + expect(33); + + QUnit.reset(); + + jQuery("#main").html(function(){ + return jQuery(this).text(); + }); + + ok( !/ 0, "Make sure text exists." ); }); test("html(Function) with incoming value", function() { @@ -984,6 +1008,11 @@ test("html(Function) with incoming value", function() { equals( val, old[i], "Make sure the incoming value is correct." ); return "bold"; }); + + // Handle the case where no comment is in the document + if ( j.length === 2 ) { + equals( null, null, "Make sure the incoming value is correct." ); + } j.find('b').removeData(); equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "bold", "Check node,textnode,comment with html()" ); @@ -1038,7 +1067,8 @@ var testRemove = function(method) { equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" ); // using contents will get comments regular, text, and comment nodes - equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" ); + // Handle the case where no comment is in the document + ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" ); jQuery("#nonnodes").contents()[method](); equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );