Added a fix, and tests, for appending empty sets of elements/strings.

This commit is contained in:
John Resig 2007-01-14 19:30:40 +00:00
parent e50a2f6ca3
commit 729396e6cf
2 changed files with 13 additions and 1 deletions

View file

@ -192,7 +192,7 @@ test("wrap(String|Element)", function() {
}); });
test("append(String|Element|Array<Element>|jQuery)", function() { test("append(String|Element|Array<Element>|jQuery)", function() {
expect(5); expect(9);
var defaultText = 'Try them out:' var defaultText = 'Try them out:'
var result = $('#first').append('<b>buga</b>'); var result = $('#first').append('<b>buga</b>');
ok( result.text() == defaultText + 'buga', 'Check if text appending works' ); ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
@ -212,6 +212,15 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
$('#sap').append($("#first, #yahoo")); $('#sap').append($("#first, #yahoo"));
ok( expected == $('#sap').text(), "Check for appending of jQuery object" ); ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
reset();
$("#sap").append( 5 );
ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
reset();
ok( $("#sap").append([]), "Check for appending an empty array." );
ok( $("#sap").append(""), "Check for appending an empty string." );
ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
}); });
test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {

View file

@ -1444,6 +1444,9 @@ jQuery.extend({
arg = div.childNodes; arg = div.childNodes;
} }
if ( arg.length === 0 )
continue;
if ( arg[0] == undefined ) if ( arg[0] == undefined )
r.push( arg ); r.push( arg );
else else