Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small parentsUntil fixes #1708

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ exports.parentsUntil = function (selector, filter) {
var untilNodes;

if (typeof selector === 'string') {
untilNode = select.select(
untilNodes = select.select(
5saviahv marked this conversation as resolved.
Show resolved Hide resolved
selector,
this.parents().toArray(),
this.options
)[0];
);
} else if (selector && selector.cheerio) {
untilNodes = selector.toArray();
} else if (selector) {
Expand Down Expand Up @@ -186,7 +186,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
);
};

Expand Down
13 changes: 13 additions & 0 deletions test/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down