A follow-up to [6578] (which stopped adding expandos to elements that didn't have...
[jquery.git] / test / unit / traversing.js
index 16f6043..2793f2f 100644 (file)
@@ -101,10 +101,10 @@ test("closest()", function() {
        isSet( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
 
        // Test .closest() limited by the context
-       var jq = jQuery("#nothiddendivchild", document.body);
-       isSet( jq.closest("html").get(), [], "Context limited." );
-       isSet( jq.closest("body").get(), [], "Context limited." );
-       isSet( jq.closest("#nothiddendiv").get(), q("nothiddendiv"), "Context not reached." );
+       var jq = jQuery("#nothiddendivchild");
+       isSet( jq.closest("html", document.body).get(), [], "Context limited." );
+       isSet( jq.closest("body", document.body).get(), [], "Context limited." );
+       isSet( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
 });
 
 test("not(Selector)", function() {
@@ -145,8 +145,8 @@ test("not(jQuery)", function() {
 
 test("andSelf()", function() {
        expect(4);
-       isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
-       isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
+       isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
+       isSet( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
        isSet( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
        isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("main", "ap", "groups"), "Check for parents and self" );
 });
@@ -157,7 +157,7 @@ test("siblings([String])", function() {
        isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
        isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
        isSet( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
-       var set = q("en", "sap", "sndp");
+       var set = q("sndp", "en", "sap");
        isSet( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
 });
 
@@ -203,7 +203,7 @@ test("prev([String])", function() {
 });
 
 test("slice()", function() {
-       expect(6);
+       expect(7);
 
        var $links = jQuery("#ap a");
 
@@ -213,8 +213,20 @@ test("slice()", function() {
        isSet( $links.slice(-1), q("mark"), "slice(-1)" );
 
        isSet( $links.eq(1), q("groups"), "eq(1)" );
-
        isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
+       isSet( $links.eq(-1), q("mark"), "eq(-1)" );
+});
+
+test("first()/last()", function() {
+       expect(4);
+
+       var $links = jQuery("#ap a"), $none = jQuery("asdf");
+
+       isSet( $links.first(), q("google"), "first()" );
+       isSet( $links.last(), q("mark"), "last()" );
+
+       isSet( $none.first(), [], "first() none" );
+       isSet( $none.last(), [], "last() none" );
 });
 
 test("map()", function() {