X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fmanipulation.js;h=49976345d55e4e3c1ccbe9171706405c5b43dbb7;hb=ac00fe5bbb2a95fdb747f76fd9dd7c58ba6a531c;hp=c942bfd38083747fc6ce74300eec8e112d2f5fe9;hpb=520f1a26845252dd6d7fd5f3b5bb7779ba91eb2c;p=jquery.git diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index c942bfd..4997634 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -4,9 +4,12 @@ var bareObj = function(value) { return value; }; var functionReturningObj = function(value) { return (function() { return value; }); }; test("text()", function() { - expect(1); + expect(2); var expected = "This link has class=\"blog\": Simon Willison's Weblog"; equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' ); + + // Check serialization of text values + equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." ); }); var testWrap = function(val) { @@ -116,6 +119,37 @@ test("wrapInner(String|Element)", function() { // testWrapInner(functionReturningObj) // }) +var testUnwrap = function() { + expect(9); + + jQuery("body").append(' '); + + var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(), + abcdef = jQuery('#unwrap span').get(); + + equals( jQuery('#unwrap1 span, #unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' ); + same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' ); + + same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' ); + + same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' ); + + same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' ); + + same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' ); + + same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' ); + same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' ); + + same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' ); + + jQuery('body > span.unwrap').remove(); +} + +test("unwrap()", function() { + testUnwrap(); +}); + var testAppend = function(valueObj) { expect(21); var defaultText = 'Try them out:' @@ -320,7 +354,7 @@ test("prependTo(String|Element|Array<Element>|jQuery)", function() { }); var testBefore = function(val) { - expect(4); + expect(6); var expected = 'This is a normal link: bugaYahoo'; jQuery('#yahoo').before(val( 'buga' )); equals( expected, jQuery('#en').text(), 'Insert String before' ); @@ -339,6 +373,10 @@ var testBefore = function(val) { expected = "This is a normal link: diveintomarkTry them out:Yahoo"; jQuery('#yahoo').before(val( jQuery("#first, #mark") )); equals( expected, jQuery('#en').text(), "Insert jQuery before" ); + + var set = jQuery("
").before("test"); + equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." ); + equals( set.length, 2, "Insert the element before the disconnected node." ); } test("before(String|Element|Array<Element>|jQuery)", function() { @@ -372,7 +410,7 @@ test("insertBefore(String|Element|Array<Element>|jQuery)", function() { }); var testAfter = function(val) { - expect(4); + expect(6); var expected = 'This is a normal link: Yahoobuga'; jQuery('#yahoo').after(val( 'buga' )); equals( expected, jQuery('#en').text(), 'Insert String after' ); @@ -391,6 +429,10 @@ var testAfter = function(val) { expected = "This is a normal link: YahoodiveintomarkTry them out:"; jQuery('#yahoo').after(val( jQuery("#first, #mark") )); equals( expected, jQuery('#en').text(), "Insert jQuery after" ); + + var set = jQuery("
").after("test"); + equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." ); + equals( set.length, 2, "Insert the element after the disconnected node." ); }; test("after(String|Element|Array<Element>|jQuery)", function() { @@ -424,7 +466,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { }); var testReplaceWith = function(val) { - expect(10); + expect(12); 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' ); @@ -445,6 +487,10 @@ var testReplaceWith = function(val) { ok( jQuery("#first")[0], 'Replace element with set of elements' ); ok( jQuery("#mark")[0], 'Replace element with set of elements' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); + + var set = jQuery("
").replaceWith(val("test")); + equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); + equals( set.length, 1, "Replace the disconnected node." ); } test("replaceWith(String|Element|Array<Element>|jQuery)", function() { @@ -559,7 +605,7 @@ test("val()", function() { equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' ); - isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); + same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' ); @@ -600,7 +646,7 @@ test("val(Function)", function() { }) var testHtml = function(valueObj) { - expect(17); + expect(20); window.debug = true; @@ -614,7 +660,7 @@ var testHtml = function(valueObj) { } ok( pass, "Set HTML" ); - window.debug = false; + delete window.debug; reset(); // using contents will get comments regular, text, and comment nodes @@ -633,6 +679,12 @@ var testHtml = function(valueObj) { equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' ); equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' ); + var $div2 = jQuery('
'), insert = "<div>hello1</div>"; + equals( $div2.html(insert).html(), insert, "Verify escaped insertion." ); + equals( $div2.html("x" + insert).html(), "x" + insert, "Verify escaped insertion." ); + equals( $div2.html(" " + insert).html(), " " + insert, "Verify escaped insertion." ); + + reset(); jQuery("#main").html(valueObj('
')); @@ -706,9 +758,11 @@ var testRemove = function(method) { var count = 0; var first = jQuery("#ap").children(":first"); - first.click(function() { count++ })[method]().appendTo("body").click(); - + var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click(); + equals( method == "remove" ? 0 : 1, count ); + + cleanUp.detach(); }; test("remove()", function() {