// 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;
// 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();
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() {
});
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" );
equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
td.attr( "colspan", "2" );
var elem, i,
obj = jQuery("div"),
- main = jQuery("#qunit-fixture"),
code = jQuery("<code/>"),
img = jQuery("<img/>"),
div = jQuery("<div/><hr/><code/><b/>"),
exec = false,
lng = "",
- expected = 21,
+ expected = 20,
attrObj = {
"text": "test",
"class": "test2",
// 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
}
});
+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 );
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 () {
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"),
- 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 });
-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);
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();
});
});
});
});
-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({
div.remove();
});
-} // if ( jQuery.fx )
+})();
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 ) {
$a.trigger("click").trigger("mouseover");
}
- jQuery( document ).on( events, "#firstp a:first" );
+ jQuery( document ).on( events, "#firstp a" );
$p.delegate( "a", events, 2 );
trigger();
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" );
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) {
// 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");
- 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() {
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) {
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;
}
test( "delegated event with delegateTarget-relative selector", function() {
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)
- markup
+ markup.find("ul").eq(0)
.on( "click", ">li>a", function() {
ok( this.id === "a0", "child li was clicked" );
})
.find("a").trigger("click").end()
.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();
});
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();
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
});
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" );
equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
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>") );
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").empty();
$input = jQuery("<input type='checkbox'/>").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("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
$radioChecked.trigger("click");
xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"),
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." );
});
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" );
- QUnit.reset();
l = jQuery("#first").children().length + 2;
jQuery("<strong>test</strong>");
jQuery("<strong>test</strong>");
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" );
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("<div/>").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("<div/>").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("<div/>");
jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
QUnit.reset();
- jQuery("<select id='prependSelect1'></select>").prependTo("form:last");
- jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("form:last");
+ jQuery("<select id='prependSelect1'></select>").prependTo("#form");
+ jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("#form");
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
});
expect( 5 );
- var clone,
- element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
+ var clone, element;
+
+ element = jQuery("<select><option>Foo</option><option value='selected' selected>Bar</option></select>");
- equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
+ 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" );
clone = element.clone();
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("<input type='text' value='foo'>");
clone = element.clone();
equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" );
ok( tmp[ 8 ], "comment" );
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");
actual.push( childNodeNames( this ) );
});
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()" );
$div = jQuery("<div />");
var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"),
expected = /^<b><i>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");
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");
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");
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;
});
});
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();
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("<div/>");
- equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
});
test("jQuery only - broken", 1, function() {
// Sizzle.error will be called but no error will be seen in oldIE
jQuery.call( null, " <div/> " );
}, function( e ) {
- return e.message.indexOf("Syntax error") >= 0;
+ return (/syntax.err/i).test( e.message );
}, "leading space invalid: $(' <div/> ')" );
});
"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");
"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");
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" );
});
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'" );
ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
- ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
- ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
- ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
- ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
ok( jQuery("#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'" );
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" );
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(
"<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) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
};
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() {
// 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() {
"<b>test</b>" +
"</a>" +
"<em></em>" +
- "</p>" ).appendTo( "body" ),
+ "</p>" ).appendTo( "#qunit-fixture" ),
filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
};
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;
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." );
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"),
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')" );
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() {
});
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" );
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() {
- 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);
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" );
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" );
- 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() {
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() {
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: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" );
test("index(no arg) #10977", function() {
expect(1);
-
- 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 );
- 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();
});