X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Ftraversing.js;h=56fed2200d0238b7366b6d07ed06e9c225fda423;hb=6c18a1becb59f1b2e64a4920967dc5cecdb296f6;hp=0636f0c33e2ac6defc180d9fcc76e08a09c4978d;hpb=f1f6bc3ec43d86f5b2a0c2b8bf711a2d35930717;p=jquery.git
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index 0636f0c..56fed22 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -1,7 +1,7 @@
-module("traversing");
+module("traversing", { teardown: moduleTeardown });
test("find(String)", function() {
- expect(3);
+ expect(5);
equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
// using contents will get comments regular, text, and comment nodes
@@ -9,6 +9,8 @@ test("find(String)", function() {
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() {
@@ -122,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)" );
@@ -136,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("
").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
});
test("closest(Array)", function() {
@@ -271,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" );
@@ -303,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" );
@@ -314,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" );
@@ -325,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" );
@@ -338,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" );
@@ -436,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" );
});