- reset();
- jQuery('form:last')
- .append('<select id="appendSelect1"></select>')
- .append('<select id="appendSelect2"><option>Test</option></select>');
-
- 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("<div/>").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(6);
- var defaultText = 'Try them out:'
- jQuery('<b>buga</b>').appendTo('#first');
- equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
- equals( jQuery('<option value="appendTest">Append Test</option>').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();
- 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('<b>buga</b>');
- equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
- equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').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('<b>buga</b>').prependTo('#first');
- equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
- equals( jQuery('<option value="prependTest">Prepend Test</option>').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('<select id="prependSelect1"></select>').prependTo('form:last');
- jQuery('<select id="prependSelect2"><option>Test</option></select>').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('<b>buga</b>');
- 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('<b>buga</b>').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('<b>buga</b>');
- 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('<b>buga</b>').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('<b id="replace">buga</b>');
- 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('<b id="replace">buga</b>').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 = [
- "<table/>", "<tr/>", "<td/>", "<div/>",
- "<button/>", "<ul/>", "<ol/>", "<li/>",
- "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
- "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
- ];
- 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();
- jQuery("tab:first", xml).text("origval");
- jQuery("tab:first", root).text("cloneval");
- equals(jQuery("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
- equals(jQuery("tab:first", root).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' );
-});
-
-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" );
-
- // 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);
-
- var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
- options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
- optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
- merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
- deep1 = { foo: { bar: true } },
- deep1copy = { foo: { bar: true } },
- deep2 = { foo: { baz: true }, foo2: document },
- deep2copy = { foo: { baz: true }, foo2: document },
- deepmerged = { foo: { bar: true, baz: true }, foo2: document };
-
- jQuery.extend(settings, options);
- isObj( settings, merged, "Check if extended: settings must be extended" );
- isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
-
- jQuery.extend(settings, null, options);
- isObj( settings, merged, "Check if extended: settings must be extended" );
- isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
-
- jQuery.extend(true, deep1, deep2);
- isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
- 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 nullUndef;
- nullUndef = jQuery.extend({}, options, { xnumber2: null });
- ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
-
- nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
- ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
-
- nullUndef = jQuery.extend({}, options, { xnumber0: null });
- ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
-
- var target = {};
- var recursive = { foo:target, bar:5 };
- jQuery.extend(true, target, recursive);
- isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
-
- var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
- equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
-
- var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
- ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
-
- var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
- ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
-
- var obj = { foo:null };
- jQuery.extend(true, obj, { foo:"notnull" } );
- equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
-
- function func() {}
- jQuery.extend(func, { key: "value" } );
- equals( func.key, "value", "Verify a function can be extended" );