Skip to content

Commit

Permalink
fix(traversing): Fix filter for {prev,next}Until (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Feb 11, 2021
1 parent 182372c commit f2615d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/api/traversing.js
Expand Up @@ -181,9 +181,9 @@ exports.parentsUntil = function (selector, filter) {
}
}, this);

return this._make(
filter ? select.filter(filter, parentNodes, this.options) : parentNodes
);
return filter
? exports.filter.call(parentNodes, filter, this)
: this._make(parentNodes);
};

/**
Expand Down Expand Up @@ -314,7 +314,7 @@ exports.nextUntil = function (selector, filterSelector) {
var untilNodes;

if (typeof selector === 'string') {
untilNode = select.select(selector, this.nextAll().get(), this.options)[0];
untilNodes = this.nextAll(selector).toArray();
} else if (selector && selector.cheerio) {
untilNodes = selector.get();
} else if (selector) {
Expand Down Expand Up @@ -432,7 +432,7 @@ exports.prevUntil = function (selector, filterSelector) {
var untilNodes;

if (typeof selector === 'string') {
untilNode = select.select(selector, this.prevAll().get(), this.options)[0];
untilNodes = this.prevAll(selector).toArray();
} else if (selector && selector.cheerio) {
untilNodes = selector.get();
} else if (selector) {
Expand Down
15 changes: 15 additions & 0 deletions test/api/traversing.js
Expand Up @@ -4,6 +4,7 @@ var food = require('../__fixtures__/fixtures').food;
var fruits = require('../__fixtures__/fixtures').fruits;
var drinks = require('../__fixtures__/fixtures').drinks;
var text = require('../__fixtures__/fixtures').text;
var forms = require('../__fixtures__/fixtures').forms;

describe('$(...)', function () {
var $;
Expand Down Expand Up @@ -266,6 +267,13 @@ describe('$(...)', function () {
expect(elems[0].attribs['class']).toBe('orange');
});

it('(selector) : should support selector matching multiple elements', function () {
var elems = $('#disabled', forms).nextUntil('option, #unnamed');
expect(elems).toHaveLength(2);
expect(elems[0].attribs['id']).toBe('submit');
expect(elems[1].attribs['id']).toBe('select');
});

it('(selector not sibling) : should return all following siblings', function () {
var elems = $('.apple').nextUntil('#vegetables');
expect(elems).toHaveLength(2);
Expand Down Expand Up @@ -404,6 +412,13 @@ describe('$(...)', function () {
expect(elems[0].attribs['class']).toBe('orange');
});

it('(selector) : should support selector matching multiple elements', function () {
var elems = $('#unnamed', forms).prevUntil('option, #disabled');
expect(elems).toHaveLength(2);
expect(elems[0].attribs['id']).toBe('select');
expect(elems[1].attribs['id']).toBe('submit');
});

it('(selector not sibling) : should return all preceding siblings', function () {
var elems = $('.sweetcorn', food).prevUntil('#fruits');
expect(elems).toHaveLength(1);
Expand Down

0 comments on commit f2615d2

Please sign in to comment.