Skip to content

Commit

Permalink
fix(traversing): parent() may fail in functions (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
5saviahv committed Jan 4, 2021
1 parent b6d3840 commit 43592d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.parent = function (selector) {
}
});

if (arguments.length) {
if (selector) {
set = exports.filter.call(set, selector, this);
}

Expand Down
6 changes: 6 additions & 0 deletions test/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ describe('$(...)', function () {
expect(result[1].attribs.id).toBe('vegetables');
});

it('(undefined) : should not throw an exception', function () {
expect(function () {
$('li').parent(undefined);
}).not.toThrow();
});

it('() : should return an empty object for top-level elements', function () {
var result = $('html').parent();
expect(result).toHaveLength(0);
Expand Down

0 comments on commit 43592d6

Please sign in to comment.