2015-08-16 06:59:58 +00:00
|
|
|
( function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
if ( !jQuery.fn.wrap ) { // no wrap module
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.module( "wrap", {
|
2013-04-08 22:00:02 +00:00
|
|
|
teardown: moduleTeardown
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// See test/unit/manipulation.js for explanation about these 2 functions
|
2015-11-13 12:27:35 +00:00
|
|
|
function manipulationBareObj( value ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
return value;
|
2013-04-09 15:45:09 +00:00
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
function manipulationFunctionReturningObj( value ) {
|
|
|
|
return function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
return value;
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
function testWrap( val, assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 19 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var defaultText, result, j, i, cacheLength;
|
|
|
|
|
|
|
|
defaultText = "Try them out:";
|
2015-08-16 06:59:58 +00:00
|
|
|
result = jQuery( "#first" ).wrap( val( "<div class='red'><span></span></div>" ) ).text();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
defaultText, result, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
|
|
|
|
result = jQuery( "#first" ).wrap( val( document.getElementById( "empty" ) ) ).parent();
|
|
|
|
assert.ok(
|
|
|
|
result.is( "ol" ), "Check for element wrapping"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
result.text(), defaultText, "Check for element wrapping"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "#check1" ).on( "click", function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
var checkbox = this;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok(
|
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
|
|
|
|
);
|
|
|
|
jQuery( checkbox ).wrap( val( "<div id='c1' style='display:none;'></div>" ) );
|
|
|
|
assert.ok(
|
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
|
|
|
|
);
|
|
|
|
} ).prop( "checked", false )[ 0 ].click();
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// using contents will get comments regular, text, and comment nodes
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "#nonnodes" ).contents();
|
|
|
|
j.wrap( val( "<i></i>" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#nonnodes > i" ).length, jQuery( "#nonnodes" )[ 0 ].childNodes.length,
|
|
|
|
"Check node,textnode,comment wraps ok"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#nonnodes > i" ).text(), j.text(),
|
|
|
|
"Check node,textnode,comment wraps doesn't hurt text"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Try wrapping a disconnected node
|
|
|
|
cacheLength = 0;
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
cacheLength++;
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<label/>" ).wrap( val( "<li/>" ) );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
cacheLength--;
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element containing a text node
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( "<div>test</div>" );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Try to wrap an element with multiple elements (should fail)
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<div><span></span></div>" ).children().wrap( "<p></p><div></div>" );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.parentNode.childNodes.length, 1,
|
|
|
|
"There should only be one element wrapping."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j.length, 1, "There should only be one element (no cloning)."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( jQuery( "<div></div>" ) );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set and event
|
2015-08-16 06:59:58 +00:00
|
|
|
result = jQuery( "<div></div>" ).on( "click", function() {
|
|
|
|
assert.ok(
|
|
|
|
true, "Event triggered."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Remove handlers on detached elements
|
|
|
|
result.off();
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( this ).off();
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( result );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
j.parent().trigger( "click" );
|
2013-04-09 15:45:09 +00:00
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(String|Element)", function( assert ) {
|
|
|
|
testWrap( manipulationBareObj, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(Function)", function( assert ) {
|
|
|
|
testWrap( manipulationFunctionReturningObj, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(Function) with index (#10177)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
var expectedIndex = 0,
|
2015-08-16 06:59:58 +00:00
|
|
|
targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( targets.length );
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.wrap( function( i ) {
|
|
|
|
assert.equal(
|
|
|
|
i, expectedIndex,
|
|
|
|
"Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
expectedIndex++;
|
|
|
|
|
|
|
|
return "<div id='wrap_index_'" + i + "'></div>";
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
var targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( targets.length * 2 );
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.wrap( "<div class='wrapper'></div>" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.each( function() {
|
|
|
|
var $this = jQuery( this );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok(
|
|
|
|
$this.parent().is( ".wrapper" ), "Check each elements parent is correct (.wrapper)"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
$this.siblings().length, 0, "Each element should be wrapped individually"
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(String)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var prev, p, result;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
prev = jQuery( "#firstp" )[ 0 ].previousSibling;
|
|
|
|
p = jQuery( "#firstp,#first" )[ 0 ].parentNode;
|
|
|
|
result = jQuery( "#firstp,#first" ).wrapAll( "<div class='red'><div class='tmp'></div></div>" );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
|
|
|
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(Element)", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var prev, p;
|
2015-08-16 06:59:58 +00:00
|
|
|
prev = jQuery( "#firstp" )[ 0 ].previousSibling;
|
|
|
|
p = jQuery( "#first" )[ 0 ].parentNode;
|
|
|
|
jQuery( "#firstp,#first" ).wrapAll( document.getElementById( "empty" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ], jQuery( "#firstp" ).parent()[ 0 ], "Same Parent"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(String)", function( assert ) {
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 6 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-12-11 16:34:05 +00:00
|
|
|
var num;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Element)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var num,
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "<div/>" );
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( document.getElementById( "empty" ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
div.wrapInner( "<span></span>" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
div.children().length, 1, "The contents were wrapped."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns String", function( assert ) {
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 6 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj;
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj,
|
2015-08-16 06:59:58 +00:00
|
|
|
div = jQuery( "<div/>" );
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( document.getElementById( "empty" ) ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
div.wrapInner( val( "<span></span>" ) );
|
|
|
|
assert.equal(
|
|
|
|
div.children().length, 1, "The contents were wrapped."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "unwrap()", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 9 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "body" ).append(
|
|
|
|
" <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
|
|
|
|
" <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'>" +
|
|
|
|
" <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'>" +
|
|
|
|
" <b><span class='unwrap unwrap3'>e</span></b>" +
|
|
|
|
" <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
var abcd = jQuery( "#unwrap1 > span, #unwrap2 > span" ).get(),
|
|
|
|
abcdef = jQuery( "#unwrap span" ).get();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#unwrap1 span" ).add( "#unwrap2 span:first-child" ).unwrap().length, 3,
|
|
|
|
"make #unwrap1 and #unwrap2 go away"
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap > span" ).get(), abcd, "all four spans should still exist"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap3 > span" ).get(),
|
|
|
|
"make all b in #unwrap3 go away"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap > span.unwrap3" ).get(),
|
|
|
|
"make #unwrap3 go away"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap" ).children().get(), abcdef, "#unwrap only contains 6 child spans"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap > span" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
|
|
|
|
"make the 6 spans become children of body"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
|
|
|
|
"can't unwrap children of body"
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).unwrap().get(), abcdef, "can't unwrap children of body"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).get(), abcdef, "body contains 6 .unwrap child spans"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "body > span.unwrap" ).remove();
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
|
|
|
|
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
$wraptarget.wrapAll( "<aside style='background-color:green'></aside>" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.notEqual(
|
|
|
|
$wraptarget.parent( "aside" ).get( 0 ).style.backgroundColor, "transparent",
|
|
|
|
"HTML5 elements created with wrapAll inherit styles"
|
|
|
|
);
|
|
|
|
assert.notEqual(
|
|
|
|
$section.get( 0 ).style.backgroundColor, "transparent",
|
|
|
|
"HTML5 elements create with jQuery( string ) inherit styles"
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapping scripts (#10470)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var script = document.createElement( "script" );
|
|
|
|
script.text = script.textContent =
|
|
|
|
"ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
document.eval10470 = false;
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );
|
|
|
|
jQuery( "#qunit-fixture script" ).wrap( "<b></b>" );
|
|
|
|
assert.strictEqual(
|
|
|
|
script.parentNode, jQuery( "#qunit-fixture > b" )[ 0 ], "correctly wrapped"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
jQuery( script ).remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
} )();
|