( function() { if ( !jQuery.fn.wrap ) { // no wrap module return; } QUnit.module( "wrap", { teardown: moduleTeardown } ); // See test/unit/manipulation.js for explanation about these 2 functions function manipulationBareObj( value ) { return value; } function manipulationFunctionReturningObj( value ) { return function() { return value; }; } function testWrap( val, assert ) { assert.expect( 19 ); var defaultText, result, j, i, cacheLength; defaultText = "Try them out:"; result = jQuery( "#first" ).wrap( val( "
" ) ).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() { var checkbox = this; assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); jQuery( checkbox ).wrap( val( "" ) ); assert.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( "" ) ); assert.equal( jQuery( "#nonnodes > i" ).length, 3, "Check node,textnode,comment wraps ok" ); assert.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( "