');
- ok( jQuery('#table caption').length, "Append caption" );
-
- reset();
- jQuery('form:last')
- .append('')
- .append('');
-
- t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- var d = jQuery("").appendTo("#nonnodes").append(j);
- equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
- ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
- d.contents().appendTo("#nonnodes");
- d.remove();
- ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
-});
-
-test("appendTo(String|Element|Array<Element>|jQuery)", function() {
- expect(7);
- var defaultText = 'Try them out:'
- jQuery('buga').appendTo('#first');
- equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
- equals( jQuery('').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
-
- reset();
- var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
- jQuery(document.getElementById('first')).appendTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for appending of element" );
-
- reset();
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
- jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
-
- reset();
- ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
-
- reset();
- expected = document.querySelectorAll ?
- "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" :
- "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
- jQuery("#first, #yahoo").appendTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
-
- reset();
- jQuery('#select1').appendTo('#foo');
- t( 'Append select', '#foo select', ['select1'] );
-});
-
-test("prepend(String|Element|Array<Element>|jQuery)", function() {
- expect(5);
- var defaultText = 'Try them out:'
- var result = jQuery('#first').prepend('buga');
- equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
- equals( jQuery('#select3').prepend('').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
-
- reset();
- var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery('#sap').prepend(document.getElementById('first'));
- equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
-
- reset();
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
- equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
-
- reset();
- expected = document.querySelectorAll ?
- "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" :
- "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery('#sap').prepend(jQuery("#first, #yahoo"));
- equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
-});
-
-test("prependTo(String|Element|Array<Element>|jQuery)", function() {
- expect(6);
- var defaultText = 'Try them out:'
- jQuery('buga').prependTo('#first');
- equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
- equals( jQuery('').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
-
- reset();
- var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
- jQuery(document.getElementById('first')).prependTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
-
- reset();
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
-
- reset();
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
- jQuery("#yahoo, #first").prependTo('#sap');
- equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
-
- reset();
- jQuery('').prependTo('form:last');
- jQuery('').prependTo('form:last');
-
- t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
-});
-
-test("before(String|Element|Array<Element>|jQuery)", function() {
- expect(4);
- var expected = 'This is a normal link: bugaYahoo';
- jQuery('#yahoo').before('buga');
- equals( expected, jQuery('#en').text(), 'Insert String before' );
-
- reset();
- expected = "This is a normal link: Try them out:Yahoo";
- jQuery('#yahoo').before(document.getElementById('first'));
- equals( expected, jQuery('#en').text(), "Insert element before" );
-
- reset();
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
- equals( expected, jQuery('#en').text(), "Insert array of elements before" );
-
- reset();
- expected = document.querySelectorAll ?
- "This is a normal link: diveintomarkTry them out:Yahoo" :
- "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery('#yahoo').before(jQuery("#first, #mark"));
- equals( expected, jQuery('#en').text(), "Insert jQuery before" );
-});
-
-test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
- expect(4);
- var expected = 'This is a normal link: bugaYahoo';
- jQuery('buga').insertBefore('#yahoo');
- equals( expected, jQuery('#en').text(), 'Insert String before' );
-
- reset();
- expected = "This is a normal link: Try them out:Yahoo";
- jQuery(document.getElementById('first')).insertBefore('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert element before" );
-
- reset();
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert array of elements before" );
-
- reset();
- expected = document.querySelectorAll ?
- "This is a normal link: diveintomarkTry them out:Yahoo" :
- "This is a normal link: Try them out:diveintomarkYahoo";
- jQuery("#first, #mark").insertBefore('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert jQuery before" );
-});
-
-test("after(String|Element|Array<Element>|jQuery)", function() {
- expect(4);
- var expected = 'This is a normal link: Yahoobuga';
- jQuery('#yahoo').after('buga');
- equals( expected, jQuery('#en').text(), 'Insert String after' );
-
- reset();
- expected = "This is a normal link: YahooTry them out:";
- jQuery('#yahoo').after(document.getElementById('first'));
- equals( expected, jQuery('#en').text(), "Insert element after" );
-
- reset();
- expected = "This is a normal link: YahooTry them out:diveintomark";
- jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
- equals( expected, jQuery('#en').text(), "Insert array of elements after" );
-
- reset();
- expected = document.querySelectorAll ?
- "This is a normal link: YahoodiveintomarkTry them out:" :
- "This is a normal link: YahooTry them out:diveintomark";
- jQuery('#yahoo').after(jQuery("#first, #mark"));
- equals( expected, jQuery('#en').text(), "Insert jQuery after" );
-});
-
-test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
- expect(4);
- var expected = 'This is a normal link: Yahoobuga';
- jQuery('buga').insertAfter('#yahoo');
- equals( expected, jQuery('#en').text(), 'Insert String after' );
-
- reset();
- expected = "This is a normal link: YahooTry them out:";
- jQuery(document.getElementById('first')).insertAfter('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert element after" );
-
- reset();
- expected = "This is a normal link: YahooTry them out:diveintomark";
- jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert array of elements after" );
-
- reset();
- expected = "This is a normal link: YahooTry them out:diveintomark";
- jQuery("#mark, #first").insertAfter('#yahoo');
- equals( expected, jQuery('#en').text(), "Insert jQuery after" );
-});
-
-test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
- expect(10);
- jQuery('#yahoo').replaceWith('buga');
- ok( jQuery("#replace")[0], 'Replace element with string' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
-
- reset();
- jQuery('#yahoo').replaceWith(document.getElementById('first'));
- ok( jQuery("#first")[0], 'Replace element with element' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
-
- reset();
- jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
- ok( jQuery("#first")[0], 'Replace element with array of elements' );
- ok( jQuery("#mark")[0], 'Replace element with array of elements' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
-
- reset();
- jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
- ok( jQuery("#first")[0], 'Replace element with set of elements' );
- ok( jQuery("#mark")[0], 'Replace element with set of elements' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
-});
-
-test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
- expect(10);
- jQuery('buga').replaceAll("#yahoo");
- ok( jQuery("#replace")[0], 'Replace element with string' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
-
- reset();
- jQuery(document.getElementById('first')).replaceAll("#yahoo");
- ok( jQuery("#first")[0], 'Replace element with element' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
-
- reset();
- jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
- ok( jQuery("#first")[0], 'Replace element with array of elements' );
- ok( jQuery("#mark")[0], 'Replace element with array of elements' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
-
- reset();
- jQuery("#first, #mark").replaceAll("#yahoo");
- ok( jQuery("#first")[0], 'Replace element with set of elements' );
- ok( jQuery("#mark")[0], 'Replace element with set of elements' );
- ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
-});
-
-test("end()", function() {
- expect(3);
- equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
- ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
-
- var x = jQuery('#yahoo');
- x.parent();
- equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
-});
-
-test("find(String)", function() {
- expect(2);
- equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
-});
-
-test("clone()", function() {
- expect(20);
- equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
- var clone = jQuery('#yahoo').clone();
- equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
- equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
-
- var cloneTags = [
- "
", "
", "
", "",
- "", "
", "", "",
- "", "", "", "",
- "", "", "", ""
- ];
- for (var i = 0; i < cloneTags.length; i++) {
- var j = jQuery(cloneTags[i]);
- equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
- }
-
- // using contents will get comments regular, text, and comment nodes
- var cl = jQuery("#nonnodes").contents().clone();
- ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
-});
-
-if (!isLocal) {
-test("clone() on XML nodes", function() {
- expect(2);
- stop();
- jQuery.get("data/dashboard.xml", function (xml) {
- var root = jQuery(xml.documentElement).clone();
- var origTab = jQuery("tab", xml).eq(0);
- var cloneTab = jQuery("tab", root).eq(0);
- origTab.text("origval");
- cloneTab.text("cloneval");
- equals(origTab.text(), "origval", "Check original XML node was correctly set");
- equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
- start();
- });
-});
-}
-
-test("is(String)", function() {
- expect(26);
- ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
- ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
- ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
- ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
- ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
- ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
- ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
- ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
- ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
- ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
- ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
- ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
- ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
- ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
- ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
- ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
- ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
- ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
- ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
- ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
- ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
- ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
-
- // test is() with comma-seperated expressions
- ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
- ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
- ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
- ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
+ // Passing a selector or nothing
+ // enabled since [6330]
+ equals( jQuery('#text2').index(), 2, "Check for index amongst siblings" );
+ equals( jQuery('#form').children().eq(4).index(), 4, "Check for index amongst siblings" );
+ equals( jQuery('#radio2').index('#form :radio') , 1, "Check for index within a selector" );
+ equals( jQuery('#form :radio').index( jQuery('#radio2') ), 1, "Check for index within a selector" );
+ equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" );
});
test("jQuery.merge()", function() {
expect(6);
-
+
var parse = jQuery.merge;
-
+
same( parse([],[]), [], "Empty arrays" );
-
+
same( parse([1],[2]), [1,2], "Basic" );
same( parse([1,2],[3,4]), [1,2,3,4], "Basic" );
-
+
same( parse([1,2],[]), [1,2], "Second empty" );
- same( parse([],[1,2]), [1,2], "First empty" );
-
+ same( parse([],[1,2]), [1,2], "First empty" );
+
// Fixed at [5998], #3641
same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
});
test("jQuery.extend(Object, Object)", function() {
- expect(20);
+ expect(23);
var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -1262,6 +466,22 @@ test("jQuery.extend(Object, Object)", function() {
isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
+ var empty = {};
+ var optionsWithLength = { foo: { length: -1 } };
+ jQuery.extend(true, empty, optionsWithLength);
+ isObj( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
+
+ empty = {};
+ var optionsWithDate = { foo: { date: new Date } };
+ jQuery.extend(true, empty, optionsWithDate);
+ isObj( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
+
+ var myKlass = function() {};
+ empty = {};
+ var optionsWithCustomObject = { foo: { date: new myKlass } };
+ jQuery.extend(true, empty, optionsWithCustomObject);
+ isObj( empty.foo, optionsWithCustomObject.foo, "Custom objects copy correctly" );
+
var nullUndef;
nullUndef = jQuery.extend({}, options, { xnumber2: null });
ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
@@ -1309,308 +529,8 @@ test("jQuery.extend(Object, Object)", function() {
isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
});
-test("val()", function() {
- expect(8);
-
- equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
- // ticket #1714 this caused a JS error in IE
- equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
- ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
-
- equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
-
- isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
-
- equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
-
- equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
-
- equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
-
-});
-
-test("val(String/Number)", function() {
- expect(6);
- document.getElementById('text1').value = "bla";
- equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
-
- jQuery("#text1").val('test');
- equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
-
- jQuery("#text1").val(67);
- equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
-
- jQuery("#select1").val("3");
- equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
-
- jQuery("#select1").val(2);
- equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.val("asdf");
- equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
- j.removeAttr("value");
-});
-
-test("html(String)", function() {
- expect(17);
-
- jQuery.scriptorder = 0;
-
- var div = jQuery("#main > div");
- div.html("test");
- var pass = true;
- for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).childNodes.length != 1 ) pass = false;
- }
- ok( pass, "Set HTML" );
-
- reset();
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.html("bold");
-
- // this is needed, or the expando added by jQuery unique will yield a different html
- j.find('b').removeData();
- equals( j.html().toLowerCase(), "bold", "Check node,textnode,comment with html()" );
-
- jQuery("#main").html("");
- jQuery("#main select").html("");
- equals( jQuery("#main select").val(), "O2", "Selected option correct" );
-
- var $div = jQuery('');
- equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
- equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
-
- reset();
-
- jQuery("#main").html('');
-
- stop();
-
- jQuery("#main").html('');
-
- jQuery("#main").html('foo ');
-
- // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
- jQuery("#main").html("