- reset();
- var prev = jQuery("#firstp")[0].previousSibling;
- var p = jQuery("#first")[0].parentNode;
- var result = jQuery('#firstp,#first').wrapAll(document.getElementById('empty'));
- equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
- equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
- equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
-});
-
-test("wrapInner(String|Element)", function() {
- expect(6);
- var num = jQuery("#first").children().length;
- var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
- equals( jQuery("#first").children().length, 1, "Only one child" );
- ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
- equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
-
- reset();
- var num = jQuery("#first").children().length;
- var result = jQuery('#first').wrapInner(document.getElementById('empty'));
- equals( jQuery("#first").children().length, 1, "Only one child" );
- ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
- equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
-});
-
-test("append(String|Element|Array<Element>|jQuery)", function() {
- expect(21);
- var defaultText = 'Try them out:'
- var result = jQuery('#first').append('<b>buga</b>');
- equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
- equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').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('#sap').append(document.getElementById('first'));
- 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('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
- 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('#sap').append(jQuery("#first, #yahoo"));
- equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
-
- reset();
- jQuery("#sap").append( 5 );
- ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
-
- reset();
- jQuery("#sap").append( " text with spaces " );
- ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
-
- reset();
- ok( jQuery("#sap").append([]), "Check for appending an empty array." );
- ok( jQuery("#sap").append(""), "Check for appending an empty string." );
- ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
-
- reset();
- jQuery("#sap").append(document.getElementById('form'));
- equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
-
- reset();
- var pass = true;
- try {
- jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
- } catch(e) {
- pass = false;
- }
-
- ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
-
- reset();
- jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
- t( 'Append legend', '#legend', ['legend'] );
-
- reset();
- jQuery('#select1').append('<OPTION>Test</OPTION>');
- equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
-
- jQuery('#table').append('<colgroup></colgroup>');
- ok( jQuery('#table colgroup').length, "Append colgroup" );
-
- jQuery('#table colgroup').append('<col/>');
- ok( jQuery('#table colgroup col').length, "Append col" );
-
- reset();
- jQuery('#table').append('<caption></caption>');
- ok( jQuery('#table caption').length, "Append caption" );
-
- 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();
- 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' );
-});
-
-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" );
-
- var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
- defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
- options1 = { xnumber2: 1, xstring2: "x" },
- options1Copy = { xnumber2: 1, xstring2: "x" },
- options2 = { xstring2: "xx", xxx: "newstringx" },
- options2Copy = { xstring2: "xx", xxx: "newstringx" },
- merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
-
- var settings = jQuery.extend({}, defaults, options1, options2);
- isObj( settings, merged2, "Check if extended: settings must be extended" );
- isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
- isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
- 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");
-});
-
-var scriptorder = 0;
-
-test("html(String)", function() {
- expect(13);
- var div = jQuery("#main > div");
- div.html("<b>test</b>");
- 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("<b>bold</b>");
-
- // this is needed, or the expando added by jQuery unique will yield a different html
- j.find('b').removeData();
- equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
-
- jQuery("#main").html("<select/>");
- jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
- equals( jQuery("#main select").val(), "O2", "Selected option correct" );
-
- var $div = jQuery('<div />');
- equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
- equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
-
- stop();
-
- jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
-
- jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
-
- // 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("<script>equals(scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
-
- setTimeout( start, 100 );
-});
-
-test("filter()", function() {
- expect(6);
- isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
- isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
- isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
- isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
- equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
-});
-
-test("closest()", function() {
- expect(4);
- isSet( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
- isSet( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
- isSet( jQuery("body").closest("div").get(), [], "closest(div)" );
- isSet( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" );
-});
-
-test("not()", function() {
- expect(11);
- equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
- equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
- isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
- isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
- isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
- equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
- isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
-
- var selects = jQuery("#form select");
- isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
-
- isSet( jQuery('#ap *').not('code'), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
- isSet( jQuery('#ap *').not('code, #mark'), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
- isSet( jQuery('#ap *').not('#mark, code'), q("google", "groups", "anchor1"), "not('ID, tag selector')");
-});
-
-test("andSelf()", function() {
- expect(4);
- isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
- isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
- isSet( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
- isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
-});
-
-test("siblings([String])", function() {
- expect(5);
- isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
- isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
- isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
- isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "name-tests", "testForm", "floatTest"), "Check for multiple filters" );
- var set = document.querySelectorAll ? q("en", "sap", "sndp") : q("sndp", "sap", "en");
- isSet( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
-});
-
-test("children([String])", function() {
- expect(3);
- isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
- isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
- isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
-});
-
-test("parent([String])", function() {
- expect(5);
- equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
- equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
- equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
- equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
- isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
-});
-
-test("parents([String])", function() {
- expect(5);
- equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
- equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
- equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
- isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
- isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
-});
-
-test("next([String])", function() {
- expect(4);
- equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
- equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
- equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
- equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
-});
-
-test("prev([String])", function() {
- expect(4);
- equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
- equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
- equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
- equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
-});
-
-test("show()", function() {
- expect(15);
- var pass = true, div = jQuery("div");
- div.show().each(function(){
- if ( this.style.display == "none" ) pass = false;
- });
- ok( pass, "Show" );
-
- jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
- var test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : jQuery.browser.msie ? "block" : "table",
- "thead" : jQuery.browser.msie ? "block" : "table-header-group",
- "tbody" : jQuery.browser.msie ? "block" : "table-row-group",
- "tr" : jQuery.browser.msie ? "block" : "table-row",
- "th" : jQuery.browser.msie ? "block" : "table-cell",
- "td" : jQuery.browser.msie ? "block" : "table-cell",
- "ul" : "block",
- "li" : jQuery.browser.msie ? "block" : "list-item"
- };
-
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- equals( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
-});
-
-test("addClass(String)", function() {
- expect(2);
- var div = jQuery("div");
- div.addClass("test");
- var pass = true;
- for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
- }
- ok( pass, "Add Class" );
-
- // using contents will get regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.addClass("asdf");
- ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
-});
-
-test("removeClass(String) - simple", function() {
- expect(4);
-
- var $divs = jQuery('div');
-
- $divs.addClass("test").removeClass("test");
-
- ok( !$divs.is('.test'), "Remove Class" );
-
- reset();
-
- $divs.addClass("test").addClass("foo").addClass("bar");
- $divs.removeClass("test").removeClass("bar").removeClass("foo");
-
- ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
-
- reset();
-
- $divs.eq(0).addClass("test").removeClass("");
- ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
-
- // using contents will get regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.removeClass("asdf");
- ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
-});
-
-test("toggleClass(String)", function() {
- expect(6);
- var e = jQuery("#firstp");
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass("test");
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass("test");
- ok( !e.is(".test"), "Assert class not present" );
-
- e.toggleClass("test", false);
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass("test", true);
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass("test", false);
- ok( !e.is(".test"), "Assert class not present" );
-});
-
-test("removeAttr(String", function() {
- expect(1);
- equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
-});
-
-test("text(String)", function() {
- expect(4);
- equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[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("hi!");
- equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
- equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
- equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );