diff --git a/test/index.html b/test/index.html
index 14e686034..cf9590a61 100644
--- a/test/index.html
+++ b/test/index.html
@@ -57,6 +57,7 @@
+
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 6093dbfb6..a15c4c5ad 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -103,234 +103,6 @@ test( "text(Function) with incoming value", function() {
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
});
-if ( jQuery.fn.wrap ) {
-
- var testWrap = function( val ) {
-
- expect( 19 );
-
- var defaultText, result, j, i, cacheLength;
-
- defaultText = "Try them out:",
- result = jQuery("#first").wrap( val("
") ).text();
-
- equal( defaultText, result, "Check for wrapping of on-the-fly html" );
- ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
-
- QUnit.reset();
- result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent();
- ok( result.is("ol"), "Check for element wrapping" );
- equal( result.text(), defaultText, "Check for element wrapping" );
-
- QUnit.reset();
- jQuery("#check1").on( "click", function() {
- var checkbox = this;
-
- ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- jQuery( checkbox ).wrap( val("") );
- ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- }).prop( "checked", false )[ 0 ].click();
-
- // using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.wrap( val("") );
-
- // Blackberry 4.6 doesn't maintain comments in the DOM
- equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
- equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
-
- // Try wrapping a disconnected node
- cacheLength = 0;
- for ( i in jQuery.cache ) {
- cacheLength++;
- }
-
- j = jQuery("").wrap( val("") );
- equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
- equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
-
- for ( i in jQuery.cache ) {
- cacheLength--;
- }
- equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
-
- // Wrap an element containing a text node
- j = jQuery("").wrap("
test
");
- equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
- equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
-
- // Try to wrap an element with multiple elements (should fail)
- j = jQuery("
").children().wrap("");
- equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
- equal( j.length, 1, "There should only be one element (no cloning)." );
- equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
-
- // Wrap an element with a jQuery set
- j = jQuery("").wrap( jQuery("") );
- equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
-
- // Wrap an element with a jQuery set and event
- result = jQuery("").on( "click", function() {
- ok( true, "Event triggered." );
-
- // Remove handlers on detached elements
- result.off();
- jQuery(this).off();
- });
-
- j = jQuery("").wrap( result );
- equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
-
- j.parent().trigger("click");
-
- // clean up attached elements
- QUnit.reset();
- };
-
- test( "wrap(String|Element)", function() {
- testWrap( manipulationBareObj );
- });
-
- test( "wrap(Function)", function() {
- testWrap( manipulationFunctionReturningObj );
- });
-
- test( "wrap(Function) with index (#10177)", function() {
- var expectedIndex = 0,
- targets = jQuery("#qunit-fixture p");
-
- expect( targets.length );
- targets.wrap(function(i) {
- equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
- expectedIndex++;
-
- return "";
- });
- });
-
- test( "wrap(String) consecutive elements (#10177)", function() {
- var targets = jQuery("#qunit-fixture p");
-
- expect( targets.length * 2 );
- targets.wrap("");
-
- targets.each(function() {
- var $this = jQuery(this);
-
- ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
- equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
- });
- });
-}
-
-if ( jQuery.fn.wrapAll ) {
-
- var testWrapAll = function( val ) {
-
- expect( 8 );
-
- var prev, p, result;
-
- prev = jQuery("#firstp")[ 0 ].previousSibling;
- p = jQuery("#firstp,#first")[ 0 ].parentNode;
- result = jQuery("#firstp,#first").wrapAll( val("
") );
-
- equal( jQuery("#first").children().length, 1, "Only one child" );
- ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-
- QUnit.reset();
- num = jQuery("#first").html("foo
test
test2
").children().length;
- result = jQuery("#first").wrapInner( val("
") );
- equal( jQuery("#first").children().length, 1, "Only one child" );
- ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-
- QUnit.reset();
- num = jQuery("#first").children().length;
- result = jQuery("#first").wrapInner( val(document.getElementById("empty")) );
- equal( jQuery("#first").children().length, 1, "Only one child" );
- ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
- equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
-
- var div = jQuery("");
- div.wrapInner( val("") );
- equal( div.children().length, 1, "The contents were wrapped." );
- equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
- };
-
- test( "wrapInner(String|Element)", function() {
- testWrapInner( manipulationBareObj );
- });
-
- test( "wrapInner(Function)", function() {
- testWrapInner( manipulationFunctionReturningObj );
- });
-}
-
-if ( jQuery.fn.unwrap ) {
-
- test( "unwrap()", function() {
-
- expect( 9 );
-
- jQuery("body").append("
ab
cd
ef
");
-
- var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
- abcdef = jQuery("#unwrap span").get();
-
- equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
- deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
-
- deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
-
- deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
-
- deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
-
- deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
-
- deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
- deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
-
- deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
-
- jQuery("body > span.unwrap").remove();
- });
-}
-
var testAppendForObject = function( valueObj, isFragment ) {
var $base,
type = isFragment ? " (DocumentFragment)" : " (Element)",
@@ -649,7 +421,7 @@ test( "append HTML5 sectioning elements (Bug #6485)", function() {
jQuery("#qunit-fixture").append("");
- article = jQuery("article"),
+ article = jQuery("article");
aside = jQuery("aside");
equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable" );
@@ -1953,22 +1725,6 @@ test( "jQuery.clone - no exceptions for object elements #9587", function() {
}
});
-if ( jQuery.fn.wrapAll ) {
-
- test( "jQuery() & wrap[Inner/All]() handle unknown elems (#10667)", function() {
-
- expect( 2 );
-
- var $wraptarget = jQuery( "
Target
" ).appendTo( "#qunit-fixture" ),
- $section = jQuery( "" ).appendTo( "#qunit-fixture" );
-
- $wraptarget.wrapAll("");
-
- notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
- notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
- });
-}
-
test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
expect( 7 );
@@ -2165,24 +1921,6 @@ test( "script evaluation (#11795)", function() {
objGlobal.ok = isOk;
});
-if ( jQuery.fn.wrap ) {
-
- test( "wrapping scripts (#10470)", function() {
-
- expect( 2 );
-
- var script = document.createElement("script");
- script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
-
- document.eval10470 = false;
- jQuery("#qunit-fixture").empty()[0].appendChild( script );
- jQuery("#qunit-fixture script").wrap("");
- strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
- jQuery( script ).remove();
- });
-
-}
-
test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function() {
expect( 10 );
diff --git a/test/unit/wrap.js b/test/unit/wrap.js
new file mode 100644
index 000000000..1775aafb6
--- /dev/null
+++ b/test/unit/wrap.js
@@ -0,0 +1,265 @@
+(function() {
+
+if ( !jQuery.fn.wrap ) { // no wrap module
+ return;
+}
+
+module( "wrap", {
+ teardown: moduleTeardown
+});
+
+// See test/unit/manipulation.js for explanation about these 2 functions
+var manipulationBareObj = function( value ) {
+ return value;
+};
+
+var manipulationFunctionReturningObj = function( value ) {
+ return (function() {
+ return value;
+ });
+};
+
+var testWrap = function( val ) {
+
+ expect( 19 );
+
+ var defaultText, result, j, i, cacheLength;
+
+ defaultText = "Try them out:";
+ result = jQuery("#first").wrap( val("
") ).text();
+
+ equal( defaultText, result, "Check for wrapping of on-the-fly html" );
+ ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
+
+ QUnit.reset();
+ result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent();
+ ok( result.is("ol"), "Check for element wrapping" );
+ equal( result.text(), defaultText, "Check for element wrapping" );
+
+ QUnit.reset();
+ jQuery("#check1").on( "click", function() {
+ var checkbox = this;
+
+ ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
+ jQuery( checkbox ).wrap( val("") );
+ ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
+ }).prop( "checked", false )[ 0 ].click();
+
+ // using contents will get comments regular, text, and comment nodes
+ j = jQuery("#nonnodes").contents();
+ j.wrap( val("") );
+
+ // Blackberry 4.6 doesn't maintain comments in the DOM
+ equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
+ equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
+
+ // Try wrapping a disconnected node
+ cacheLength = 0;
+ for ( i in jQuery.cache ) {
+ cacheLength++;
+ }
+
+ j = jQuery("").wrap( val("") );
+ equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
+ equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
+
+ for ( i in jQuery.cache ) {
+ cacheLength--;
+ }
+ equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
+
+ // Wrap an element containing a text node
+ j = jQuery("").wrap("
test
");
+ equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
+ equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
+
+ // Try to wrap an element with multiple elements (should fail)
+ j = jQuery("
").children().wrap("");
+ equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
+ equal( j.length, 1, "There should only be one element (no cloning)." );
+ equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
+
+ // Wrap an element with a jQuery set
+ j = jQuery("").wrap( jQuery("") );
+ equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+
+ // Wrap an element with a jQuery set and event
+ result = jQuery("").on( "click", function() {
+ ok( true, "Event triggered." );
+
+ // Remove handlers on detached elements
+ result.off();
+ jQuery(this).off();
+ });
+
+ j = jQuery("").wrap( result );
+ equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+
+ j.parent().trigger("click");
+
+ // clean up attached elements
+ QUnit.reset();
+};
+
+test( "wrap(String|Element)", function() {
+ testWrap( manipulationBareObj );
+});
+
+test( "wrap(Function)", function() {
+ testWrap( manipulationFunctionReturningObj );
+});
+
+test( "wrap(Function) with index (#10177)", function() {
+ var expectedIndex = 0,
+ targets = jQuery("#qunit-fixture p");
+
+ expect( targets.length );
+ targets.wrap(function(i) {
+ equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
+ expectedIndex++;
+
+ return "";
+ });
+});
+
+test( "wrap(String) consecutive elements (#10177)", function() {
+ var targets = jQuery("#qunit-fixture p");
+
+ expect( targets.length * 2 );
+ targets.wrap("");
+
+ targets.each(function() {
+ var $this = jQuery(this);
+
+ ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
+ equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
+ });
+});
+
+var testWrapAll = function( val ) {
+
+ expect( 8 );
+
+ var prev, p, result;
+
+ prev = jQuery("#firstp")[ 0 ].previousSibling;
+ p = jQuery("#firstp,#first")[ 0 ].parentNode;
+ result = jQuery("#firstp,#first").wrapAll( val("