diff --git a/lib/api/traversing.js b/lib/api/traversing.js index 0dd60854c6..1d4163b0fb 100644 --- a/lib/api/traversing.js +++ b/lib/api/traversing.js @@ -152,11 +152,7 @@ exports.parentsUntil = function (selector, filter) { var untilNodes; if (typeof selector === 'string') { - untilNode = select.select( - selector, - this.parents().toArray(), - this.options - )[0]; + untilNodes = this.parents(selector).toArray(); } else if (selector && selector.cheerio) { untilNodes = selector.toArray(); } else if (selector) { @@ -186,7 +182,7 @@ exports.parentsUntil = function (selector, filter) { }, this); return this._make( - filter ? select.select(filter, parentNodes, this.options) : parentNodes + filter ? select.filter(filter, parentNodes, this.options) : parentNodes ); }; diff --git a/test/api/traversing.js b/test/api/traversing.js index e10bbba26c..bf2e579edd 100644 --- a/test/api/traversing.js +++ b/test/api/traversing.js @@ -550,6 +550,11 @@ describe('$(...)', function () { expect(result).toHaveLength(0); }); + it('(selector) : Less simple parentsUntil check with selector', function () { + var result = $('#fruits').parentsUntil('html, body'); + expect(result.eq(0).attr('id')).toBe('food'); + }); + it('(selector not parent) : should return all parents', function () { var result = $('.orange').parentsUntil('.apple'); expect(result).toHaveLength(4); @@ -568,6 +573,14 @@ describe('$(...)', function () { expect(result[0].attribs.id).toBe('vegetables'); }); + it('(selector, filter) : Multiple-filtered parentsUntil check', function () { + var result = $('.orange').parentsUntil('html', 'ul,body'); + expect(result).toHaveLength(3); + expect(result.eq(0).prop('tagName')).toBe('BODY'); + expect(result.eq(1).attr('id')).toBe('food'); + expect(result.eq(2).attr('id')).toBe('fruits'); + }); + it('() : should return empty object when called on an empty object', function () { var result = $('.saladbar').parentsUntil(); expect(result).toHaveLength(0);