No ticket: Revise unit tests in anticipation of Sizzle-free builds

This commit is contained in:
Richard Gibson 2013-02-18 23:52:29 -05:00
parent 9338a69e30
commit 59f5adb622
11 changed files with 208 additions and 161 deletions

View File

@ -172,11 +172,11 @@ var Globals = (function() {
// instead of asserting every time a test has leaked sometime in the past // instead of asserting every time a test has leaked sometime in the past
var oldCacheLength = 0, var oldCacheLength = 0,
oldFragmentsLength = 0, oldFragmentsLength = 0,
oldTimersLength = 0,
oldActive = 0, oldActive = 0,
expectedDataKeys = {}, expectedDataKeys = {},
splice = [].splice,
reset = QUnit.reset, reset = QUnit.reset,
ajaxSettings = jQuery.ajaxSettings; ajaxSettings = jQuery.ajaxSettings;
@ -286,6 +286,20 @@ var Globals = (function() {
// Reset data register // Reset data register
expectedDataKeys = {}; 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 // Allow QUnit.reset to clean up any attached elements before checking for leaks
QUnit.reset(); QUnit.reset();
@ -309,17 +323,6 @@ var Globals = (function() {
equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
oldFragmentsLength = fragmentsLength; 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() { QUnit.done(function() {

View File

@ -376,7 +376,7 @@ test( "attr(String, Object)", function() {
}); });
var table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"), var table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
td = table.find("td:first"); td = table.find("td").eq(0);
td.attr( "rowspan", "2" ); td.attr( "rowspan", "2" );
equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" ); equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
td.attr( "colspan", "2" ); td.attr( "colspan", "2" );

View File

@ -28,13 +28,12 @@ test("jQuery()", function() {
var elem, i, var elem, i,
obj = jQuery("div"), obj = jQuery("div"),
main = jQuery("#qunit-fixture"),
code = jQuery("<code/>"), code = jQuery("<code/>"),
img = jQuery("<img/>"), img = jQuery("<img/>"),
div = jQuery("<div/><hr/><code/><b/>"), div = jQuery("<div/><hr/><code/><b/>"),
exec = false, exec = false,
lng = "", lng = "",
expected = 21, expected = 20,
attrObj = { attrObj = {
"text": "test", "text": "test",
"class": "test2", "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 // 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)" ); 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 // 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 // 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() { test( "selector state", function() {
expect( 18 ); expect( 18 );

View File

@ -616,12 +616,12 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
expect(4); expect(4);
var $checkedtest = jQuery("#checkedtest"); var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery.css(elem, "height");
jQuery.css($checkedtest[0], "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("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox 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 () { test("internal ref to elem.runtimeStyle (bug #7608)", function () {

View File

@ -296,8 +296,8 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
test( "table dimensions", 2, function() { test( "table dimensions", 2, function() {
var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"), var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
tdElem = table.find("tr:eq(0) td:eq(0)"), tdElem = table.find("td").first(),
colElem = table.find("col:eq(1)").width( 300 ); colElem = table.find("col").first().width( 300 );
table.find("td").css({ "margin": 0, "padding": 0 }); table.find("td").css({ "margin": 0, "padding": 0 });

29
test/unit/effects.js vendored
View File

@ -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() { test("sanity check", function() {
expect(1); expect(1);
@ -1055,12 +1067,11 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
stop(); stop();
var $checkedtest = jQuery("#checkedtest"); var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery(elem).show("fast");
$checkedtest.hide().show("fast", function() { $checkedtest.hide().show("fast", function() {
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." ); ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." ); ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
start(); 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" ); var foo = jQuery( "#foo" );
foo.animate({ foo.animate({
@ -2014,4 +2025,4 @@ test( ".finish() calls finish of custom queue functions", function() {
div.remove(); div.remove();
}); });
} // if ( jQuery.fx ) })();

View File

@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){
test("on/off(Object), delegate/undelegate(String, Object)", function() { test("on/off(Object), delegate/undelegate(String, Object)", function() {
expect(6); expect(6);
var clickCounter = 0, mouseoverCounter = 0, var clickCounter = 0,
$p = jQuery("#firstp"), $a = $p.find("a:first"); mouseoverCounter = 0,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);
var events = { var events = {
"click": function( event ) { "click": function( event ) {
@ -326,7 +328,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
$a.trigger("click").trigger("mouseover"); $a.trigger("click").trigger("mouseover");
} }
jQuery( document ).on( events, "#firstp a:first" ); jQuery( document ).on( events, "#firstp a" );
$p.delegate( "a", events, 2 ); $p.delegate( "a", events, 2 );
trigger(); trigger();
@ -339,7 +341,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
equal( clickCounter, 4, "undelegate" ); equal( clickCounter, 4, "undelegate" );
equal( mouseoverCounter, 4, "undelegate" ); equal( mouseoverCounter, 4, "undelegate" );
jQuery( document ).off( events, "#firstp a:first" ); jQuery( document ).off( events, "#firstp a" );
trigger(); trigger();
equal( clickCounter, 4, "off" ); equal( clickCounter, 4, "off" );
@ -349,19 +351,21 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
test("on/delegate immediate propagation", function() { test("on/delegate immediate propagation", function() {
expect(2); expect(2);
var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick; var lastClick,
$p = jQuery("#firstp"),
$a = $p.find("a").eq(0);
lastClick = ""; lastClick = "";
jQuery( document ).on( "click", "#firstp a:first", function(e) { jQuery( document ).on( "click", "#firstp a", function(e) {
lastClick = "click1"; lastClick = "click1";
e.stopImmediatePropagation(); e.stopImmediatePropagation();
}); });
jQuery( document ).on( "click", "#firstp a:first", function(e) { jQuery( document ).on( "click", "#firstp a", function(e) {
lastClick = "click2"; lastClick = "click2";
}); });
$a.trigger( "click" ); $a.trigger( "click" );
equal( lastClick, "click1", "on stopImmediatePropagation" ); equal( lastClick, "click1", "on stopImmediatePropagation" );
jQuery( document ).off( "click", "#firstp a:first" ); jQuery( document ).off( "click", "#firstp a" );
lastClick = ""; lastClick = "";
$p.delegate( "a", "click", function(e) { $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 // Make sure events stick with appendTo'd elements (which are cloned) #2027
jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture"); jQuery("<a href='#fail' class='test'>test</a>").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() { test("bind(), multi-namespaced events", function() {
@ -996,7 +1000,7 @@ test("trigger(type, [data], [fn])", function() {
var pass = true, elem2; var pass = true, elem2;
try { try {
elem2 = jQuery("#form input:first"); elem2 = jQuery("#form input").eq(0);
elem2.get(0).style.display = "none"; elem2.get(0).style.display = "none";
elem2.trigger("focus"); elem2.trigger("focus");
} catch(e) { } catch(e) {
@ -1006,7 +1010,7 @@ test("trigger(type, [data], [fn])", function() {
pass = true; pass = true;
try { 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) { } catch (e) {
pass = false; pass = false;
} }
@ -1717,10 +1721,24 @@ test("jQuery.off using dispatched jQuery.Event", function() {
test( "delegated event with delegateTarget-relative selector", function() { test( "delegated event with delegateTarget-relative selector", function() {
expect(3); expect(3);
var markup = jQuery("<ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul>").appendTo("#qunit-fixture"); var markup = jQuery("<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>").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) // Positional selector (#11315)
markup markup.find("ul").eq(0)
.on( "click", ">li>a", function() { .on( "click", ">li>a", function() {
ok( this.id === "a0", "child li was clicked" ); 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("a").trigger("click").end()
.find("#ul0").off(); .find("#ul0").off();
// Non-positional selector (#12383)
markup = markup.wrap("<div />").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(); markup.remove();
}); });
@ -2558,12 +2561,12 @@ test( "make sure events cloned correctly", 18, function() {
clone = fixture.clone( true ); 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.find("#check1").trigger( "change", true ); // 3 events should fire
clone.remove(); clone.remove();
clone = fixture.clone( true, true ); 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 clone.find("#check1").trigger( "change", true ); // 3 events should fire
fixture.off(); fixture.off();
@ -2573,11 +2576,11 @@ test( "make sure events cloned correctly", 18, function() {
p.trigger("click"); // 0 should be fired p.trigger("click"); // 0 should be fired
checkbox.trigger("change"); // 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.find("#check1").trigger( "change", true ); // 3 events should fire
clone.remove(); 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 clone.find("#check1").trigger("change"); // 0 events should fire
}); });

View File

@ -300,7 +300,7 @@ test( "unwrap()", function() {
var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
abcdef = jQuery("#unwrap 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("#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" ); 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." ); equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") ); jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") );
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("<optgroup label='optgroup'><option>optgroup</option></optgroup>") ); jQuery("#select1").append( valueObj("<optgroup label='optgroup'><option>optgroup</option></optgroup>") );
equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" ); 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"); $table = jQuery("#table");
@ -490,7 +490,7 @@ var testAppend = function( valueObj ) {
$input = jQuery("<input type='checkbox'/>").prop( "checked", true ).appendTo("#testForm"); $input = jQuery("<input type='checkbox'/>").prop( "checked", true ).appendTo("#testForm");
equal( $input[ 0 ].checked, true, "A checked checkbox that is appended stays checked" ); 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(); $radioParent = $radioChecked.parent();
$radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent ); $radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
$radioChecked.trigger("click"); $radioChecked.trigger("click");
@ -601,12 +601,12 @@ test( "replaceWith on XML document (#9960)", function() {
xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"), xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"),
xml1 = jQuery( xmlDoc1 ), xml1 = jQuery( xmlDoc1 ),
xml2 = jQuery( xmlDoc2 ), xml2 = jQuery( xmlDoc2 ),
scxml1 = jQuery( ":first", xml1 ), scxml1 = jQuery( "scxml", xml1 ),
scxml2 = jQuery( ":first", xml2 ); scxml2 = jQuery( "scxml", xml2 );
scxml1.replaceWith( scxml2 ); 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." ); equal( newNode.length, 1, "ReplaceWith not working on document nodes." );
}); });
@ -734,7 +734,6 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" ); equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
QUnit.reset();
l = jQuery("#first").children().length + 2; l = jQuery("#first").children().length + 2;
jQuery("<strong>test</strong>"); jQuery("<strong>test</strong>");
jQuery("<strong>test</strong>"); jQuery("<strong>test</strong>");
@ -748,7 +747,6 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
jQuery( document.getElementById("first") ).appendTo("#sap"); jQuery( document.getElementById("first") ).appendTo("#sap");
equal( jQuery("#sap").text(), expected, "Check for appending of element" ); 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"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap"); jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap");
equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
@ -756,35 +754,29 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
QUnit.reset(); QUnit.reset();
ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); 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:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
jQuery("#yahoo, #first").appendTo("#sap"); jQuery("#yahoo, #first").appendTo("#sap");
equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset();
jQuery("#select1").appendTo("#foo"); jQuery("#select1").appendTo("#foo");
t( "Append select", "#foo select", [ "select1" ] ); t( "Append select", "#foo select", [ "select1" ] );
QUnit.reset();
div = jQuery("<div/>").on( "click", function() { div = jQuery("<div/>").on( "click", function() {
ok( true, "Running a cloned click." ); ok( true, "Running a cloned click." );
}); });
div.appendTo("#qunit-fixture, #moretests"); div.appendTo("#qunit-fixture, #moretests");
jQuery("#qunit-fixture div:last").trigger("click"); jQuery("#qunit-fixture div").last().trigger("click");
jQuery("#moretests div:last").trigger("click"); jQuery("#moretests div").last().trigger("click");
QUnit.reset();
div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests"); div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
equal( div.length, 2, "appendTo returns the inserted elements" ); equal( div.length, 2, "appendTo returns the inserted elements" );
div.addClass("test"); div.addClass("test");
ok( jQuery("#qunit-fixture div:last").hasClass("test"), "appendTo element was modified after the insertion" ); 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" ); ok( jQuery("#moretests div").last().hasClass("test"), "appendTo element was modified after the insertion" );
QUnit.reset();
div = jQuery("<div/>"); div = jQuery("<div/>");
jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div ); jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
@ -923,8 +915,8 @@ test( "prependTo(String|Element|Array<Element>|jQuery)", function() {
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery("<select id='prependSelect1'></select>").prependTo("form:last"); jQuery("<select id='prependSelect1'></select>").prependTo("#form");
jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("form:last"); jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("#form");
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] ); t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
}); });
@ -1422,10 +1414,11 @@ test( "clone(form element) (Bug #3879, #6655)", function() {
expect( 5 ); expect( 5 );
var clone, var clone, element;
element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); element = jQuery("<select><option>Foo</option><option value='selected' selected>Bar</option></select>");
equal( element.clone().find("option").filter(function() { return this.selected; }).val(), "selected", "Selected option cloned correctly" );
element = jQuery("<input type='checkbox' value='foo'>").attr( "checked", "checked" ); element = jQuery("<input type='checkbox' value='foo'>").attr( "checked", "checked" );
clone = element.clone(); 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.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
equal( clone[ 0 ].defaultValue, "foo", "Checked input defaultValue 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("<input type='text' value='foo'>"); element = jQuery("<input type='text' value='foo'>");
clone = element.clone(); clone = element.clone();
equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" ); equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" );
@ -1550,7 +1540,7 @@ var testHtml = function( valueObj ) {
ok( tmp[ 8 ], "comment" ); ok( tmp[ 8 ], "comment" );
actual = []; expected = []; actual = []; expected = [];
fixture.find("> div").html( valueObj("<b>test</b>") ).each(function() { fixture.children("div").html( valueObj("<b>test</b>") ).each(function() {
expected.push("B"); expected.push("B");
actual.push( childNodeNames( this ) ); 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." ); equal( null, null, "Make sure the incoming value is correct." );
} }
j.find("b").removeData();
equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
$div = jQuery("<div />"); $div = jQuery("<div />");
@ -1696,15 +1685,21 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"), var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"),
expected = /^<b><i>text<\/i><\/b>$/i; expected = /^<b><i>text<\/i><\/b>$/i;
// Attach jQuery and Sizzle data (the latter by conducting a non-qSA search) // Attach jQuery and Sizzle data (the latter with a non-qSA nth-child)
try {
$content.find(":nth-child(1):lt(4)").data( "test", true ); $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.clone( false )[ 0 ].innerHTML ), "clone()" );
ok( expected.test( $content.html() ), "html()" ); ok( expected.test( $content.html() ), "html()" );
}); });
var testRemove = function( method ) { var testRemove = function( method ) {
var first = jQuery("#ap").children(":first"); var first = jQuery("#ap").children().first();
first.data("foo", "bar"); first.data("foo", "bar");
@ -1742,7 +1737,7 @@ test( "remove() event cleaning ", 1, function() {
var count, first, cleanUp; var count, first, cleanUp;
count = 0; count = 0;
first = jQuery("#ap").children(":first"); first = jQuery("#ap").children().first();
cleanUp = first.on( "click", function() { cleanUp = first.on( "click", function() {
count++; count++;
}).remove().appendTo("#qunit-fixture").trigger("click"); }).remove().appendTo("#qunit-fixture").trigger("click");
@ -1761,7 +1756,7 @@ test( "detach() event cleaning ", 1, function() {
var count, first, cleanUp; var count, first, cleanUp;
count = 0; count = 0;
first = jQuery("#ap").children(":first"); first = jQuery("#ap").children().first();
cleanUp = first.on( "click", function() { cleanUp = first.on( "click", function() {
count++; count++;
}).detach().appendTo("#qunit-fixture").trigger("click"); }).detach().appendTo("#qunit-fixture").trigger("click");
@ -2136,7 +2131,7 @@ test( "script evaluation (#11795)", function() {
scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") ); scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") );
deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" ); deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" );
fixture.append( scriptsOut.detach() ); 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; objGlobal.ok = isOk;
}); });

View File

@ -64,15 +64,20 @@ test("attributes - jQuery only", function() {
}); });
test("disconnected nodes", function() { test("disconnected nodes", function() {
expect( 4 ); expect( 1 );
var $div = jQuery("<div/>");
equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
});
test("disconnected nodes - jQuery only", function() {
expect( 3 );
var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach(); var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach();
equal( $opt.val(), "whipit", "option value" ); equal( $opt.val(), "whipit", "option value" );
equal( $opt.is(":selected"), false, "unselected option" ); equal( $opt.is(":selected"), false, "unselected option" );
$opt.prop("selected", true); $opt.prop("selected", true);
equal( $opt.is(":selected"), true, "selected option" ); equal( $opt.is(":selected"), true, "selected option" );
var $div = jQuery("<div/>");
equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
}); });
test("jQuery only - broken", 1, function() { 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 // Sizzle.error will be called but no error will be seen in oldIE
jQuery.call( null, " <div/> " ); jQuery.call( null, " <div/> " );
}, function( e ) { }, function( e ) {
return e.message.indexOf("Syntax error") >= 0; return (/syntax.err/i).test( e.message );
}, "leading space invalid: $(' <div/> ')" ); }, "leading space invalid: $(' <div/> ')" );
}); });

View File

@ -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", "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"); "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", "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"); "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=", "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"); "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=", "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"); "Check input serialization as query string");

View File

@ -1,13 +1,20 @@
module("traversing", { teardown: moduleTeardown }); module("traversing", { teardown: moduleTeardown });
test( "find(String)", function() { test( "find(String)", function() {
expect( 7 ); expect( 1 );
equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" ); 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(); var j = jQuery("#nonnodes").contents();
equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); 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" ); 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("> 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" ); 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() { 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("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("#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(".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("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" ); 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("#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(0), "Expected false for an invalid expression - 0" );
ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" ); 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=\"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=\"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=\"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)" ); test("is() against window|document (#10178)", function() {
ok( !jQuery(document).is("a"), "Checking is on a document does not throw an exception(#10178)" ); expect(2);
ok( !jQuery(window).is("a"), "Checking is on a window does not throw an exception" );
ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" ); ok( !jQuery(document).is("a"), "Checking is on a document does not throw an exception" );
}); });
test("is(jQuery)", function() { 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("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("#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'" ); 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("#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("#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("#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 // Some raw elements
ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" ); 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'" ); 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() { test("is() with positional selectors", function() {
expect(23); expect(24);
var html = jQuery( var html = jQuery(
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>" "<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
).appendTo( "body" ), ).appendTo( "#qunit-fixture" ),
isit = function(sel, match, expect) { isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" ); 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:last", true );
isit( "#posp em", "#posp a em:eq(2)", false ); 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() { test("index()", function() {
@ -175,15 +189,15 @@ test("index(Object|String|undefined)", function() {
// enabled since [5500] // enabled since [5500]
equal( elements.index( elements ), 0, "Pass in a jQuery object" ); equal( elements.index( elements ), 0, "Pass in a jQuery object" );
equal( elements.index( elements.eq(1) ), 1, "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 // Passing a selector or nothing
// enabled since [6330] // enabled since [6330]
equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); 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("#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("#radio2").index("#form input[type='radio']") , 1, "Check for index within a selector" );
equal( jQuery("#form :radio").index( jQuery("#radio2") ), 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 :text") , -1, "Check for index not found 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() { test("filter(Selector|undefined)", function() {
@ -247,7 +261,7 @@ test("filter() with positional selectors", function() {
"<b>test</b>" + "<b>test</b>" +
"</a>" + "</a>" +
"<em></em>" + "<em></em>" +
"</p>" ).appendTo( "body" ), "</p>" ).appendTo( "#qunit-fixture" ),
filterit = function(sel, filter, length) { filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); 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:gt(0)", 0 );
filterit( "#posp .seconda", "#posp a:lt(5)", 1 ); filterit( "#posp .seconda", "#posp a:lt(5)", 1 );
filterit( "#posp .seconda", "#posp a:lt(1)", 1 ); filterit( "#posp .seconda", "#posp a:lt(1)", 1 );
html.remove();
}); });
test("closest()", function() { test("closest()", function() {
expect( 15 ); expect( 13 );
var jq; var jq;
@ -288,9 +301,6 @@ test("closest()", function() {
deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" ); 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("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 // Test .closest() limited by the context
jq = jQuery("#nothiddendivchild"); jq = jQuery("#nothiddendivchild");
deepEqual( jq.closest("html", document.body).get(), [], "Context limited." ); 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)" ); 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() { test("closest(jQuery)", function() {
expect(8); expect(8);
var $child = jQuery("#nothiddendivchild"), 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')" ); 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(".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("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").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID 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(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(0).get(), all, "not(0) should have no effect");
deepEqual( jQuery("p").not("").get(), all, "not('') 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() { test("not(Element)", function() {
@ -435,11 +453,9 @@ test("addBack()", function() {
}); });
test("siblings([String])", function() { test("siblings([String])", function() {
expect(8); expect(6);
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); 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("#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" ); deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
var set = q("sndp", "en", "sap"); var set = q("sndp", "en", "sap");
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
@ -447,13 +463,23 @@ test("siblings([String])", function() {
equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" ); equal( jQuery("<a/>").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() { test("children([String])", function() {
expect(3); expect(2);
deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); 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" ); 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() { test("parent([String])", function() {
expect(6); 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().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(".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" ); 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("#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" ); 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(); 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("<div>text<a id='element'></a></div>").contents().eq(0).nextAll().attr("id"), "element", "Text node nextAll check" ); equal( jQuery("<div>text<a id='element'></a></div>").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").get(), elems.slice(1).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").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.not(":first").filter("input,select").get(), "Multi-source, 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() { 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("#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("#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(".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" ); 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, #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", "input").get(), elems.slice(0, -1).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").get(), elems.slice(0, -1).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", "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" ); 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() { test("contents()", function() {
@ -589,12 +615,12 @@ test("contents()", function() {
jQuery(ibody).append("<div>init text</div>"); jQuery(ibody).append("<div>init text</div>");
equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); 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"); jQuery("div", ibody).last().text("div text");
equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" ); 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).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" ); 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() { test("index(no arg) #10977", function() {
expect(2); expect(2);
var $list = jQuery("<ul id='indextest'><li>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>"); var $list = jQuery("<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
jQuery("#qunit-fixture").append( $list ); 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(); $list.remove();
var fragment = document.createDocumentFragment(), var fragment = document.createDocumentFragment(),