Merge branch 'fix-7853-add-context' of https://github.com/dmethvin/jquery into dmethv...
[jquery.git] / test / unit / traversing.js
index f5c88e4..56fed22 100644 (file)
@@ -1,12 +1,16 @@
-module("traversing");
+module("traversing", { teardown: moduleTeardown });
 
 test("find(String)", function() {
-       expect(2);
+       expect(5);
        equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
 
        // using contents will get comments regular, text, and comment nodes
        var j = jQuery("#nonnodes").contents();
        equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
+
+       same( jQuery("#main").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
+       same( jQuery("#main").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
+       same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
 });
 
 test("is(String)", function() {
@@ -120,7 +124,7 @@ test("filter(jQuery)", function() {
 })
 
 test("closest()", function() {
-       expect(10);
+       expect(11);
        same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
        same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
        same( jQuery("body").closest("div").get(), [], "closest(div)" );
@@ -134,10 +138,12 @@ test("closest()", function() {
        same( jq.closest("html", document.body).get(), [], "Context limited." );
        same( jq.closest("body", document.body).get(), [], "Context limited." );
        same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
-       
+
        //Test that .closest() returns unique'd set
        equals( jQuery('#main p').closest('#main').length, 1, "Closest should return a unique set" );
-       
+
+       // Test on disconnected node
+       equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
 });
 
 test("closest(Array)", function() {
@@ -269,9 +275,9 @@ test("parents([String])", function() {
 
 test("parentsUntil([String])", function() {
        expect(9);
-       
+
        var parents = jQuery("#groups").parents();
-       
+
        same( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
        same( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
        same( jQuery("#groups").parentsUntil("#html").get(), parents.not(':last').get(), "Simple parentsUntil check" );
@@ -301,9 +307,9 @@ test("prev([String])", function() {
 
 test("nextAll([String])", function() {
        expect(4);
-       
+
        var elems = jQuery('#form').children();
-       
+
        same( jQuery("#label-for").nextAll().get(), elems.not(':first').get(), "Simple nextAll check" );
        same( jQuery("#label-for").nextAll('input').get(), elems.not(':first').filter('input').get(), "Filtered nextAll check" );
        same( jQuery("#label-for").nextAll('input,select').get(), elems.not(':first').filter('input,select').get(), "Multiple-filtered nextAll check" );
@@ -312,9 +318,9 @@ test("nextAll([String])", function() {
 
 test("prevAll([String])", function() {
        expect(4);
-       
+
        var elems = jQuery( jQuery('#form').children().slice(0, 12).get().reverse() );
-       
+
        same( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
        same( jQuery("#area1").prevAll('input').get(), elems.filter('input').get(), "Filtered prevAll check" );
        same( jQuery("#area1").prevAll('input,select').get(), elems.filter('input,select').get(), "Multiple-filtered prevAll check" );
@@ -323,9 +329,9 @@ test("prevAll([String])", function() {
 
 test("nextUntil([String])", function() {
        expect(11);
-       
+
        var elems = jQuery('#form').children().slice( 2, 12 );
-       
+
        same( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
        same( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
        same( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" );
@@ -336,15 +342,15 @@ test("nextUntil([String])", function() {
        same( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" );
        equals( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" );
        same( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
-       
+
        same( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
 });
 
 test("prevUntil([String])", function() {
        expect(10);
-       
+
        var elems = jQuery("#area1").prevAll();
-       
+
        same( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
        same( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
        same( jQuery("#area1").prevUntil("label").get(), elems.not(':last').get(), "Simple prevUntil check" );
@@ -434,12 +440,13 @@ test("add(String|Element|Array|undefined)", function() {
 
 test("add(String, Context)", function() {
        expect(6);
-
-       equals( jQuery(document).add("#form").length, 2, "Make sure that using regular context document still works." );
-       equals( jQuery(document.body).add("#form").length, 2, "Using a body context." );
-       equals( jQuery(document.body).add("#html").length, 1, "Using a body context." );
-
-       equals( jQuery(document).add("#form", document).length, 2, "Use a passed in document context." );
-       equals( jQuery(document).add("#form", document.body).length, 2, "Use a passed in body context." );
-       equals( jQuery(document).add("#html", document.body).length, 1, "Use a passed in body context." );
+       
+       deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " );
+       deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" );
+       deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" );
+
+       var ctx = document.getElementById("firstp");
+       deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " );
+       deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" );
+       deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" );
 });