From 78c803f1b5198e77f77231516db3912aa9a87055 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 24 Apr 2013 11:38:23 -0400 Subject: [PATCH] Fix #13819: .parent sort direction (cherry picked from commit 6a816ec95fd96d130a4af67a28873d9daa66a328) --- src/traversing.js | 2 +- test/unit/traversing.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/traversing.js b/src/traversing.js index 5e9fe1943..6f68e7821 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -201,7 +201,7 @@ jQuery.each({ } // Reverse order for parents* and prev* - if ( name[ 0 ] === "p" ) { + if ( name[ 0 ] === "p" && name !== "parent" ) { matched.reverse(); } } diff --git a/test/unit/traversing.js b/test/unit/traversing.js index e45ab75a5..b35a5c3cc 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -673,6 +673,32 @@ test("contents()", function() { equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); }); +test("sort direction", function() { + expect( 12 ); + + var elems = jQuery("#ap, #select1 > *, #moretests > form"), + methodDirections = { + parent: false, + parents: true, + parentsUntil: true, + next: false, + prev: true, + nextAll: false, + prevAll: true, + nextUntil: false, + prevUntil: true, + siblings: false, + children: false, + contents: false + }; + + jQuery.each( methodDirections, function( method, reversed ) { + var actual = elems[ method ]().get(), + forward = jQuery.unique( [].concat( actual ) ); + deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method ); + }); +}); + test("add(String|Element|Array|undefined)", function() { expect( 15 ); -- 2.39.5