diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 130aa3fe2..2ac75e53b 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -1,11 +1,21 @@
-module("manipulation", { teardown: moduleTeardown });
+module( "manipulation", {
+ teardown: moduleTeardown
+});
// Ensure that an extended Array prototype doesn't break jQuery
-Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); };
+Array.prototype.arrayProtoFn = function( arg ) {
+ throw("arrayProtoFn should not be called");
+};
-var manipulationBareObj = function(value) { return value; };
-var manipulationFunctionReturningObj = function(value) { return (function() { return value; }); };
+var manipulationBareObj = function( value ) {
+ return value;
+};
+var manipulationFunctionReturningObj = function( value ) {
+ return (function() {
+ return value;
+ });
+};
/*
======== local reference =======
@@ -19,62 +29,73 @@ var manipulationFunctionReturningObj = function(value) { return (function() { re
Returns a function that returns the value
*/
-test("text()", function() {
- expect(5);
- var expected = "This link has class=\"blog\": Simon Willison's Weblog";
+test( "text()", function() {
+
+ expect( 5 );
+
+ var expected, frag, $newLineTest;
+
+ expected = "This link has class=\"blog\": Simon Willison's Weblog";
equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." );
// Check serialization of text values
equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
- notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724).");
+ notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724)." );
// Retrieve from document fragments #10864
- var frag = document.createDocumentFragment();
- frag.appendChild( document.createTextNode("foo") );
+ frag = document.createDocumentFragment();
+ frag.appendChild( document.createTextNode("foo") );
- equal( jQuery( frag ).text(), "foo", "Document Fragment Text node was retreived from .text().");
+ equal( jQuery(frag).text(), "foo", "Document Fragment Text node was retreived from .text()." );
- var $newLineTest = jQuery("
");
+ equal( jQuery("#foo").text(val)[ 0 ].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
// using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.text(valueObj("hi!"));
- equal( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
- equal( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
+ j = jQuery("#nonnodes").contents();
+ j.text( valueObj("hi!") );
+ equal( jQuery( j[ 0 ] ).text(), "hi!", "Check node,textnode,comment with text()" );
+ equal( j[ 1 ].nodeValue, " there ", "Check node,textnode,comment with text()" );
// Blackberry 4.6 doesn't maintain comments in the DOM
- equal( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" );
+ equal( jQuery("#nonnodes")[ 0 ].childNodes.length < 3 ? 8 : j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" );
};
-test("text(String)", function() {
- testText(manipulationBareObj);
+test( "text(String)", function() {
+ testText( manipulationBareObj );
});
-test("text(Function)", function() {
- testText(manipulationFunctionReturningObj);
+test( "text(Function)", function() {
+ testText( manipulationFunctionReturningObj );
});
-test("text(Function) with incoming value", function() {
- expect(2);
+test( "text(Function) with incoming value", function() {
+
+ expect( 2 );
var old = "This link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#sap").text(function(i, val) {
+ jQuery("#sap").text(function( i, val ) {
equal( val, old, "Make sure the incoming value is correct." );
return "foobar";
});
@@ -82,75 +103,81 @@ test("text(Function) with incoming value", function() {
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
});
-var testWrap = function(val) {
- expect(19);
- var defaultText = "Try them out:";
- var result = jQuery("#first").wrap(val( "
" )).text();
+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();
+ 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").click(function() {
var checkbox = this;
+
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- jQuery(checkbox).wrap(val( "" ));
+ jQuery( checkbox ).wrap( val("") );
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- }).prop( "checked", false )[0].click();
+ }).prop( "checked", false )[ 0 ].click();
// using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.wrap(val( "" ));
+ 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").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
- var cacheLength = 0;
- for (var i in jQuery.cache) {
+ 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" );
+ 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) {
+ for ( i in jQuery.cache ) {
cacheLength--;
}
- equal(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
+ 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." );
+ 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[ 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." );
+ 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." );
+ j = jQuery("").wrap( jQuery("") );
+ equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
// Wrap an element with a jQuery set and event
- result = jQuery("").click(function(){
- ok(true, "Event triggered.");
+ result = jQuery("").click(function() {
+ ok( true, "Event triggered." );
// Remove handlers on detached elements
result.unbind();
jQuery(this).unbind();
});
- j = jQuery("").wrap(result);
- equal( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+ j = jQuery("").wrap( result );
+ equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
j.parent().trigger("click");
@@ -158,19 +185,19 @@ var testWrap = function(val) {
QUnit.reset();
};
-test("wrap(String|Element)", function() {
- testWrap(manipulationBareObj);
+test( "wrap(String|Element)", function() {
+ testWrap( manipulationBareObj );
});
-test("wrap(Function)", function() {
- testWrap(manipulationFunctionReturningObj);
+test( "wrap(Function)", function() {
+ testWrap( manipulationFunctionReturningObj );
});
-test("wrap(Function) with index (#10177)", function() {
+test( "wrap(Function) with index (#10177)", function() {
var expectedIndex = 0,
- targets = jQuery("#qunit-fixture p");
+ targets = jQuery("#qunit-fixture p");
- expect(targets.length);
+ expect( targets.length );
targets.wrap(function(i) {
equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
expectedIndex++;
@@ -179,10 +206,10 @@ test("wrap(Function) with index (#10177)", function() {
});
});
-test("wrap(String) consecutive elements (#10177)", function() {
+test( "wrap(String) consecutive elements (#10177)", function() {
var targets = jQuery("#qunit-fixture p");
- expect(targets.length * 2);
+ expect( targets.length * 2 );
targets.wrap("");
targets.each(function() {
@@ -193,69 +220,80 @@ test("wrap(String) consecutive elements (#10177)", function() {
});
});
-var testWrapAll = function(val) {
- expect(8);
- var prev = jQuery("#firstp")[0].previousSibling;
- var p = jQuery("#firstp,#first")[0].parentNode;
-
- var result = jQuery("#firstp,#first").wrapAll(val( "
" ));
+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("