diff --git a/test/data/testrunner.js b/test/data/testrunner.js index aa7c13019..ddbe2b09f 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -172,11 +172,11 @@ var Globals = (function() { // instead of asserting every time a test has leaked sometime in the past var oldCacheLength = 0, oldFragmentsLength = 0, - oldTimersLength = 0, oldActive = 0, expectedDataKeys = {}, + splice = [].splice, reset = QUnit.reset, ajaxSettings = jQuery.ajaxSettings; @@ -286,6 +286,20 @@ var Globals = (function() { // Reset data register expectedDataKeys = {}; + // Check for (and clean up, if possible) incomplete animations/requests/etc. + if ( jQuery.timers && jQuery.timers.length !== 0 ) { + equal( jQuery.timers.length, 0, "No timers are still running" ); + splice.call( jQuery.timers, 0, jQuery.timers.length ); + jQuery.fx.stop(); + } + if ( jQuery.active !== undefined && jQuery.active !== oldActive ) { + equal( jQuery.active, oldActive, "No AJAX requests are still active" ); + if ( ajaxTest.abort ) { + ajaxTest.abort("active requests"); + } + oldActive = jQuery.active; + } + // Allow QUnit.reset to clean up any attached elements before checking for leaks QUnit.reset(); @@ -309,17 +323,6 @@ var Globals = (function() { equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); oldFragmentsLength = fragmentsLength; } - if ( jQuery.timers && jQuery.timers.length !== oldTimersLength ) { - equal( jQuery.timers.length, oldTimersLength, "No timers are still running" ); - oldTimersLength = jQuery.timers.length; - } - if ( jQuery.active !== undefined && jQuery.active !== oldActive ) { - equal( jQuery.active, 0, "No AJAX requests are still active" ); - if ( ajaxTest.abort ) { - ajaxTest.abort("active requests"); - } - oldActive = jQuery.active; - } }; QUnit.done(function() { diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 2626fa022..67ef17472 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -376,7 +376,7 @@ test( "attr(String, Object)", function() { }); var table = jQuery("#table").append("cellcellcellcellcell"), - td = table.find("td:first"); + td = table.find("td").eq(0); td.attr( "rowspan", "2" ); equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" ); td.attr( "colspan", "2" ); diff --git a/test/unit/core.js b/test/unit/core.js index 3fe3a2301..0a9227afb 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -28,13 +28,12 @@ test("jQuery()", function() { var elem, i, obj = jQuery("div"), - main = jQuery("#qunit-fixture"), code = jQuery(""), img = jQuery(""), div = jQuery("

"), exec = false, lng = "", - expected = 21, + expected = 20, attrObj = { "text": "test", "class": "test2", @@ -78,8 +77,6 @@ test("jQuery()", function() { // can actually yield more than one, when iframes are included, the window is an array as well equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); - deepEqual( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); - /* // disabled since this test was doing nothing. i tried to fix it but i'm not sure // what the expected behavior should even be. FF returns "\n" for the text node @@ -154,6 +151,13 @@ test("jQuery()", function() { } }); +test("jQuery(selector, context)", function() { + expect(3); + deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" ); + deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" ); + deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); +}); + test( "selector state", function() { expect( 18 ); diff --git a/test/unit/css.js b/test/unit/css.js index 27069f8a3..e8ce75b02 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -616,12 +616,12 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct expect(4); var $checkedtest = jQuery("#checkedtest"); - // IE6 was clearing "checked" in jQuery.css(elem, "height"); jQuery.css($checkedtest[0], "height"); - ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." ); - ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." ); - ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); - ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); + + ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." ); + ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." ); + ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." ); + ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." ); }); test("internal ref to elem.runtimeStyle (bug #7608)", function () { diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 680b08320..64094c2e5 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -296,8 +296,8 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() { test( "table dimensions", 2, function() { var table = jQuery("
a
a
").appendTo("#qunit-fixture"), - tdElem = table.find("tr:eq(0) td:eq(0)"), - colElem = table.find("col:eq(1)").width( 300 ); + tdElem = table.find("td").first(), + colElem = table.find("col").first().width( 300 ); table.find("td").css({ "margin": 0, "padding": 0 }); diff --git a/test/unit/effects.js b/test/unit/effects.js index 8c56581db..791e28bcf 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -1,6 +1,18 @@ -if ( jQuery.fx ) { +(function() { -module("effects", { teardown: moduleTeardown }); +// Can't test what ain't there +if ( !jQuery.fx ) { + return; +} + +var off = jQuery.fx.off; + +module("effects", { + teardown: function() { + jQuery.fx.off = off; + return moduleTeardown.apply( this, arguments ); + } +}); test("sanity check", function() { expect(1); @@ -1055,12 +1067,11 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () stop(); var $checkedtest = jQuery("#checkedtest"); - // IE6 was clearing "checked" in jQuery(elem).show("fast"); $checkedtest.hide().show("fast", function() { - ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." ); - ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." ); - ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); - ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); + ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." ); + ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." ); + ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." ); + ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." ); start(); }); }); @@ -1485,7 +1496,7 @@ test( "animate should set display for disconnected nodes", function() { }); }); -asyncTest("Animation callback should not show animated element as animated (#7157)", 1, function() { +asyncTest("Animation callback should not show animated element as :animated (#7157)", 1, function() { var foo = jQuery( "#foo" ); foo.animate({ @@ -2014,4 +2025,4 @@ test( ".finish() calls finish of custom queue functions", function() { div.remove(); }); -} // if ( jQuery.fx ) +})(); diff --git a/test/unit/event.js b/test/unit/event.js index f5dd149a3..6be4eb8e7 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){ test("on/off(Object), delegate/undelegate(String, Object)", function() { expect(6); - var clickCounter = 0, mouseoverCounter = 0, - $p = jQuery("#firstp"), $a = $p.find("a:first"); + var clickCounter = 0, + mouseoverCounter = 0, + $p = jQuery("#firstp"), + $a = $p.find("a").eq(0); var events = { "click": function( event ) { @@ -326,7 +328,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { $a.trigger("click").trigger("mouseover"); } - jQuery( document ).on( events, "#firstp a:first" ); + jQuery( document ).on( events, "#firstp a" ); $p.delegate( "a", events, 2 ); trigger(); @@ -339,7 +341,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { equal( clickCounter, 4, "undelegate" ); equal( mouseoverCounter, 4, "undelegate" ); - jQuery( document ).off( events, "#firstp a:first" ); + jQuery( document ).off( events, "#firstp a" ); trigger(); equal( clickCounter, 4, "off" ); @@ -349,19 +351,21 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() { test("on/delegate immediate propagation", function() { expect(2); - var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick; + var lastClick, + $p = jQuery("#firstp"), + $a = $p.find("a").eq(0); lastClick = ""; - jQuery( document ).on( "click", "#firstp a:first", function(e) { + jQuery( document ).on( "click", "#firstp a", function(e) { lastClick = "click1"; e.stopImmediatePropagation(); }); - jQuery( document ).on( "click", "#firstp a:first", function(e) { + jQuery( document ).on( "click", "#firstp a", function(e) { lastClick = "click2"; }); $a.trigger( "click" ); equal( lastClick, "click1", "on stopImmediatePropagation" ); - jQuery( document ).off( "click", "#firstp a:first" ); + jQuery( document ).off( "click", "#firstp a" ); lastClick = ""; $p.delegate( "a", "click", function(e) { @@ -490,7 +494,7 @@ test("bind(), namespaced events, cloned events", 18, function() { // Make sure events stick with appendTo'd elements (which are cloned) #2027 jQuery("test").on( "click", function(){ return false; }).appendTo("#qunit-fixture"); - ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); + ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); }); test("bind(), multi-namespaced events", function() { @@ -996,7 +1000,7 @@ test("trigger(type, [data], [fn])", function() { var pass = true, elem2; try { - elem2 = jQuery("#form input:first"); + elem2 = jQuery("#form input").eq(0); elem2.get(0).style.display = "none"; elem2.trigger("focus"); } catch(e) { @@ -1006,7 +1010,7 @@ test("trigger(type, [data], [fn])", function() { pass = true; try { - jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test"); + jQuery("#qunit-fixture table").eq(0).bind("test:test", function(){}).trigger("test:test"); } catch (e) { pass = false; } @@ -1717,10 +1721,24 @@ test("jQuery.off using dispatched jQuery.Event", function() { test( "delegated event with delegateTarget-relative selector", function() { expect(3); - var markup = jQuery("
").appendTo("#qunit-fixture"); + var markup = jQuery("
").appendTo("#qunit-fixture"); + + // Non-positional selector (#12383) + markup.find("#ul0") + .on( "click", "div li a", function() { + ok( false, "div is ABOVE the delegation point!" ); + }) + .on( "click", "ul a", function() { + ok( false, "ul IS the delegation point!" ); + }) + .on( "click", "li.test a", function() { + ok( true, "li.test is below the delegation point." ); + }) + .find("#a0_0").trigger("click").end() + .off("click"); // Positional selector (#11315) - markup + markup.find("ul").eq(0) .on( "click", ">li>a", function() { ok( this.id === "a0", "child li was clicked" ); }) @@ -1732,21 +1750,6 @@ test( "delegated event with delegateTarget-relative selector", function() { .find("a").trigger("click").end() .find("#ul0").off(); - // Non-positional selector (#12383) - markup = markup.wrap("
").parent(); - markup - .find("#ul0") - .on( "click", "div li a", function() { - ok( false, "div is ABOVE the delegation point!" ); - }) - .on( "click", "ul a", function() { - ok( false, "ul is the delegation point!" ); - }) - .on( "click", "li.test a", function() { - ok( true, "li.test is below the delegation point." ); - }) - .find("#a0_0").trigger("click"); - markup.remove(); }); @@ -2558,12 +2561,12 @@ test( "make sure events cloned correctly", 18, function() { clone = fixture.clone( true ); - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire clone.remove(); clone = fixture.clone( true, true ); - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire fixture.off(); @@ -2573,11 +2576,11 @@ test( "make sure events cloned correctly", 18, function() { p.trigger("click"); // 0 should be fired checkbox.trigger("change"); // 0 should be fired - clone.find("p:first").trigger( "click", true ); // 3 events should fire + clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire clone.find("#check1").trigger( "change", true ); // 3 events should fire clone.remove(); - clone.find("p:first").trigger("click"); // 0 should be fired + clone.find("p").eq(0).trigger("click"); // 0 should be fired clone.find("#check1").trigger("change"); // 0 events should fire }); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 01d53a0a1..20d017b25 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -300,7 +300,7 @@ test( "unwrap()", function() { var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), abcdef = jQuery("#unwrap span").get(); - equal( jQuery("#unwrap1 span").add("#unwrap2 span:first").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); + equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); @@ -452,11 +452,11 @@ var testAppend = function( valueObj ) { equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." ); jQuery("#select1").append( valueObj("") ); - equal( jQuery("#select1 option:last").text(), "Test", "Appending OPTION (all caps)" ); + equal( jQuery("#select1 option:last-child").text(), "Test", "Appending OPTION (all caps)" ); jQuery("#select1").append( valueObj("") ); equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" ); - equal( jQuery("#select1 option:last").text(), "optgroup", "Appending optgroup" ); + equal( jQuery("#select1 option").last().text(), "optgroup", "Appending optgroup" ); $table = jQuery("#table"); @@ -490,7 +490,7 @@ var testAppend = function( valueObj ) { $input = jQuery("").prop( "checked", true ).appendTo("#testForm"); equal( $input[ 0 ].checked, true, "A checked checkbox that is appended stays checked" ); - $radioChecked = jQuery("input:radio[name='R1']").eq( 1 ); + $radioChecked = jQuery("input[type='radio'][name='R1']").eq( 1 ); $radioParent = $radioChecked.parent(); $radioUnchecked = jQuery("").appendTo( $radioParent ); $radioChecked.trigger("click"); @@ -601,12 +601,12 @@ test( "replaceWith on XML document (#9960)", function() { xmlDoc2 = jQuery.parseXML(""), xml1 = jQuery( xmlDoc1 ), xml2 = jQuery( xmlDoc2 ), - scxml1 = jQuery( ":first", xml1 ), - scxml2 = jQuery( ":first", xml2 ); + scxml1 = jQuery( "scxml", xml1 ), + scxml2 = jQuery( "scxml", xml2 ); scxml1.replaceWith( scxml2 ); - newNode = jQuery( ":first>state[id='provisioning3']", xml1 ); + newNode = jQuery( "scxml>state[id='provisioning3']", xml1 ); equal( newNode.length, 1, "ReplaceWith not working on document nodes." ); }); @@ -734,7 +734,6 @@ test( "appendTo(String|Element|Array|jQuery)", function() { equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); equal( jQuery("").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" ); - QUnit.reset(); l = jQuery("#first").children().length + 2; jQuery("test"); jQuery("test"); @@ -748,7 +747,6 @@ test( "appendTo(String|Element|Array|jQuery)", function() { jQuery( document.getElementById("first") ).appendTo("#sap"); equal( jQuery("#sap").text(), expected, "Check for appending of element" ); - QUnit.reset(); expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap"); equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); @@ -756,35 +754,29 @@ test( "appendTo(String|Element|Array|jQuery)", function() { QUnit.reset(); ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); - QUnit.reset(); expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; jQuery("#yahoo, #first").appendTo("#sap"); equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); - QUnit.reset(); jQuery("#select1").appendTo("#foo"); t( "Append select", "#foo select", [ "select1" ] ); - QUnit.reset(); div = jQuery("
").on( "click", function() { ok( true, "Running a cloned click." ); }); div.appendTo("#qunit-fixture, #moretests"); - jQuery("#qunit-fixture div:last").trigger("click"); - jQuery("#moretests div:last").trigger("click"); + jQuery("#qunit-fixture div").last().trigger("click"); + jQuery("#moretests div").last().trigger("click"); - QUnit.reset(); div = jQuery("
").appendTo("#qunit-fixture, #moretests"); equal( div.length, 2, "appendTo returns the inserted elements" ); div.addClass("test"); - ok( jQuery("#qunit-fixture div:last").hasClass("test"), "appendTo element was modified after the insertion" ); - ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" ); - - QUnit.reset(); + ok( jQuery("#qunit-fixture div").last().hasClass("test"), "appendTo element was modified after the insertion" ); + ok( jQuery("#moretests div").last().hasClass("test"), "appendTo element was modified after the insertion" ); div = jQuery("
"); jQuery("ab").filter("span").appendTo( div ); @@ -923,8 +915,8 @@ test( "prependTo(String|Element|Array|jQuery)", function() { equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); QUnit.reset(); - jQuery("").prependTo("form:last"); - jQuery("").prependTo("form:last"); + jQuery("").prependTo("#form"); + jQuery("").prependTo("#form"); t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] ); }); @@ -1422,10 +1414,11 @@ test( "clone(form element) (Bug #3879, #6655)", function() { expect( 5 ); - var clone, - element = jQuery(""); + var clone, element; - equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); + element = jQuery(""); + + equal( element.clone().find("option").filter(function() { return this.selected; }).val(), "selected", "Selected option cloned correctly" ); element = jQuery("").attr( "checked", "checked" ); clone = element.clone(); @@ -1433,9 +1426,6 @@ test( "clone(form element) (Bug #3879, #6655)", function() { equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); equal( clone[ 0 ].defaultValue, "foo", "Checked input defaultValue cloned correctly" ); - // defaultChecked also gets set now due to setAttribute in attr, is this check still valid? - // equal( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" ); - element = jQuery(""); clone = element.clone(); equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" ); @@ -1550,7 +1540,7 @@ var testHtml = function( valueObj ) { ok( tmp[ 8 ], "comment" ); actual = []; expected = []; - fixture.find("> div").html( valueObj("test") ).each(function() { + fixture.children("div").html( valueObj("test") ).each(function() { expected.push("B"); actual.push( childNodeNames( this ) ); }); @@ -1656,7 +1646,6 @@ test( "html(Function) with incoming value", function() { equal( null, null, "Make sure the incoming value is correct." ); } - j.find("b").removeData(); equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "bold", "Check node,textnode,comment with html()" ); $div = jQuery("
"); @@ -1696,15 +1685,21 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function() var $content = jQuery("
text
").appendTo("#qunit-fixture"), expected = /^text<\/i><\/b>$/i; - // Attach jQuery and Sizzle data (the latter by conducting a non-qSA search) - $content.find(":nth-child(1):lt(4)").data( "test", true ); + // Attach jQuery and Sizzle data (the latter with a non-qSA nth-child) + try { + $content.find(":nth-child(1):lt(4)").data( "test", true ); + + // But don't break on a non-Sizzle build + } catch( e ) { + $content.find("*").data( "test", true ); + } ok( expected.test( $content.clone( false )[ 0 ].innerHTML ), "clone()" ); ok( expected.test( $content.html() ), "html()" ); }); var testRemove = function( method ) { - var first = jQuery("#ap").children(":first"); + var first = jQuery("#ap").children().first(); first.data("foo", "bar"); @@ -1742,7 +1737,7 @@ test( "remove() event cleaning ", 1, function() { var count, first, cleanUp; count = 0; - first = jQuery("#ap").children(":first"); + first = jQuery("#ap").children().first(); cleanUp = first.on( "click", function() { count++; }).remove().appendTo("#qunit-fixture").trigger("click"); @@ -1761,7 +1756,7 @@ test( "detach() event cleaning ", 1, function() { var count, first, cleanUp; count = 0; - first = jQuery("#ap").children(":first"); + first = jQuery("#ap").children().first(); cleanUp = first.on( "click", function() { count++; }).detach().appendTo("#qunit-fixture").trigger("click"); @@ -2136,7 +2131,7 @@ test( "script evaluation (#11795)", function() { scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") ); deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" ); fixture.append( scriptsOut.detach() ); - deepEqual( fixture.find("> script").get(), scriptsOut.get(), "Scripts detached without reevaluation" ); + deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" ); objGlobal.ok = isOk; }); diff --git a/test/unit/selector.js b/test/unit/selector.js index 22d7305eb..0cfba2834 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -64,15 +64,20 @@ test("attributes - jQuery only", function() { }); test("disconnected nodes", function() { - expect( 4 ); + expect( 1 ); + + var $div = jQuery("
"); + equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." ); +}); + +test("disconnected nodes - jQuery only", function() { + expect( 3 ); + var $opt = jQuery("").attr("value", "whipit").appendTo("#qunit-fixture").detach(); equal( $opt.val(), "whipit", "option value" ); equal( $opt.is(":selected"), false, "unselected option" ); $opt.prop("selected", true); equal( $opt.is(":selected"), true, "selected option" ); - - var $div = jQuery("
"); - equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." ); }); test("jQuery only - broken", 1, function() { @@ -83,7 +88,7 @@ test("jQuery only - broken", 1, function() { // Sizzle.error will be called but no error will be seen in oldIE jQuery.call( null, "
" ); }, function( e ) { - return e.message.indexOf("Syntax error") >= 0; + return (/syntax.err/i).test( e.message ); }, "leading space invalid: $('
')" ); }); diff --git a/test/unit/serialize.js b/test/unit/serialize.js index eff2a0086..63607a323 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -121,7 +121,7 @@ test("serialize()", function() { "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "Check form serialization as query string"); - equal( jQuery("#form :input").serialize(), + equal( jQuery("input,select,textarea,button", "#form").serialize(), "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "Check input serialization as query string"); @@ -129,7 +129,7 @@ test("serialize()", function() { "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "Check form serialization as query string"); - equal( jQuery("#testForm :input").serialize(), + equal( jQuery("input,select,textarea,button", "#testForm").serialize(), "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "Check input serialization as query string"); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 087abdc37..48560dbf6 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -1,13 +1,20 @@ module("traversing", { teardown: moduleTeardown }); test( "find(String)", function() { - expect( 7 ); - equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" ); + expect( 1 ); + equal( jQuery("#foo").find(".blogTest").text(), "Yahoo", "Basic selector" ); +}); + +test( "find(String) under non-elements", function() { + expect( 2 ); - // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); equal( j.find("div").andSelf().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" ); +}); + +test( "find(leading combinator)", function() { + expect( 4 ); deepEqual( jQuery("#qunit-fixture").find("> div").get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" ); deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q( "foo", "moretests" ), "find child elements" ); @@ -42,7 +49,7 @@ test( "find(node|jQuery object)", function() { }); test("is(String|undefined)", function() { - expect(30); + expect(23); 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'" ); @@ -57,10 +64,6 @@ test("is(String|undefined)", function() { 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" ); @@ -73,15 +76,16 @@ test("is(String|undefined)", function() { 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" ); +}); - ok( !jQuery(window).is("a"), "Checking is on a window does not throw an exception(#10178)" ); - ok( !jQuery(document).is("a"), "Checking is on a document does not throw an exception(#10178)" ); - - ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" ); +test("is() against window|document (#10178)", function() { + expect(2); + ok( !jQuery(window).is("a"), "Checking is on a window does not throw an exception" ); + ok( !jQuery(document).is("a"), "Checking is on a document does not throw an exception" ); }); test("is(jQuery)", function() { - expect(21); + expect(19); ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" ); ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" ); ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" ); @@ -95,8 +99,6 @@ test("is(jQuery)", function() { ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" ); ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" ); ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" ); - ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" ); - ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" ); // Some raw elements ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" ); @@ -107,12 +109,24 @@ test("is(jQuery)", function() { ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); }); +test("is() with :has() selectors", function() { + expect(6); + + 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( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" ); + ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" ); +}); + test("is() with positional selectors", function() { - expect(23); + expect(24); var html = jQuery( "

firsttest

" - ).appendTo( "body" ), + ).appendTo( "#qunit-fixture" ), isit = function(sel, match, expect) { equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" ); }; @@ -144,7 +158,7 @@ test("is() with positional selectors", function() { isit( "#posp em", "#posp a em:last", true ); isit( "#posp em", "#posp a em:eq(2)", false ); - html.remove(); + ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" ); }); test("index()", function() { @@ -175,15 +189,15 @@ test("index(Object|String|undefined)", function() { // enabled since [5500] equal( elements.index( elements ), 0, "Pass in a jQuery object" ); equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); - equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); + equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); // Passing a selector or nothing // enabled since [6330] equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" ); - equal( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" ); - equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); - equal( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" ); + equal( jQuery("#radio2").index("#form input[type='radio']") , 1, "Check for index within a selector" ); + equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); + equal( jQuery("#radio2").index("#form input[type='text']") , -1, "Check for index not found within a selector" ); }); test("filter(Selector|undefined)", function() { @@ -247,7 +261,7 @@ test("filter() with positional selectors", function() { "test" + "" + "" + - "

" ).appendTo( "body" ), + "

" ).appendTo( "#qunit-fixture" ), filterit = function(sel, filter, length) { equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); }; @@ -275,11 +289,10 @@ test("filter() with positional selectors", function() { filterit( "#posp .seconda", "#posp a:gt(0)", 0 ); filterit( "#posp .seconda", "#posp a:lt(5)", 1 ); filterit( "#posp .seconda", "#posp a:lt(1)", 1 ); - html.remove(); }); test("closest()", function() { - expect( 15 ); + expect( 13 ); var jq; @@ -288,9 +301,6 @@ test("closest()", function() { deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" ); deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" ); - deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" ); - deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); - // Test .closest() limited by the context jq = jQuery("#nothiddendivchild"); deepEqual( jq.closest("html", document.body).get(), [], "Context limited." ); @@ -313,6 +323,13 @@ test("closest()", function() { deepEqual( jq.contents().closest("*").get(), jq.get(), "Text node input (#13332)" ); }); +test("closest() with positional selectors", function() { + expect( 2 ); + + deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" ); + deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); +}); + test("closest(jQuery)", function() { expect(8); var $child = jQuery("#nothiddendivchild"), @@ -334,11 +351,6 @@ test("not(Selector|undefined)", function() { equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" ); deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); - deepEqual( - jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(), - q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"), - "not('complex selector')" - ); deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); @@ -349,6 +361,12 @@ test("not(Selector|undefined)", function() { deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect"); deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect"); deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect"); + + deepEqual( + jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(), + q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"), + "not('complex selector')" + ); }); test("not(Element)", function() { @@ -435,11 +453,9 @@ test("addBack()", function() { }); test("siblings([String])", function() { - expect(8); + expect(6); deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" ); - deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); - deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" ); var set = q("sndp", "en", "sap"); deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); @@ -447,13 +463,23 @@ test("siblings([String])", function() { equal( jQuery("").siblings().length, 0, "Detached elements have no siblings (#11370)" ); }); +test("siblings([String]) - jQuery only", function() { + expect(2); + deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); + deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); +}); + test("children([String])", function() { - expect(3); + expect(2); deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); - deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" ); }); +test("children([String]) - jQuery only", function() { + expect(1); + deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); +}); + test("parent([String])", function() { expect(6); @@ -486,7 +512,7 @@ test("parentsUntil([String])", function() { deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); - deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" ); + deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.slice(0, -1).get(), "Simple parentsUntil check" ); equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); deepEqual( jQuery("#nonnodes").contents().eq(1).parentsUntil("#html").eq(0).get(), q("nonnodes"), "Text node parentsUntil check" ); deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); @@ -520,11 +546,11 @@ test("nextAll([String])", function() { var elems = jQuery("#form").children(); - deepEqual( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" ); + deepEqual( jQuery("#label-for").nextAll().get(), elems.slice(1).get(), "Simple nextAll check" ); equal( jQuery("").contents().eq(0).nextAll().attr("id"), "element", "Text node nextAll check" ); - deepEqual( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" ); - deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" ); - deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); + deepEqual( jQuery("#label-for").nextAll("input").get(), elems.slice(1).filter("input").get(), "Filtered nextAll check" ); + deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multiple-filtered nextAll check" ); + deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); }); test("prevAll([String])", function() { @@ -567,14 +593,14 @@ test("prevUntil([String])", function() { deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); deepEqual( jQuery("#nonnodes").contents().eq(1).prevUntil().get(), q("nonnodesElement"), "Text node prevUntil with no selector (prevAll)" ); deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); - deepEqual( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label").get(), elems.slice(0, -1).get(), "Simple prevUntil check" ); equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); - deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" ); - deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" ); - deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.slice(0, -1).not("button").get(), "Filtered prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.slice(0, -1).not("input").get(), "Filtered prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multiple-filtered prevUntil check" ); equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); - deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" ); + deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multi-source, multiple-filtered prevUntil check" ); }); test("contents()", function() { @@ -589,12 +615,12 @@ test("contents()", function() { jQuery(ibody).append("
init text
"); equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); - equal( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" ); + equal( jQuery("div", ibody).last().text(), "init text", "Add text to div in IFrame" ); - jQuery("div:last", ibody).text("div text"); - equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" ); + jQuery("div", ibody).last().text("div text"); + equal( jQuery("div", ibody).last().text(), "div text", "Add text to div in IFrame" ); - jQuery("div:last", ibody).remove(); + jQuery("div", ibody).last().remove(); equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" ); equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); @@ -680,9 +706,9 @@ test("eq('-1') #10616", function() { test("index(no arg) #10977", function() { expect(2); - var $list = jQuery("
  • THIS ONE
  • a
  • b
  • c
"); + var $list = jQuery("
  • THIS ONE
  • a
  • b
  • c
"); jQuery("#qunit-fixture").append( $list ); - strictEqual ( jQuery( "#indextest li:not(.one,.two)" ).index() , 0, "No Argument Index Check" ); + strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" ); $list.remove(); var fragment = document.createDocumentFragment(),