Skip to content

Commit 43592d6

Browse files
authored
fix(traversing): parent() may fail in functions (#1637)
1 parent b6d3840 commit 43592d6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/api/traversing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ exports.parent = function (selector) {
8686
}
8787
});
8888

89-
if (arguments.length) {
89+
if (selector) {
9090
set = exports.filter.call(set, selector, this);
9191
}
9292

test/api/traversing.js

+6
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ describe('$(...)', function () {
619619
expect(result[1].attribs.id).toBe('vegetables');
620620
});
621621

622+
it('(undefined) : should not throw an exception', function () {
623+
expect(function () {
624+
$('li').parent(undefined);
625+
}).not.toThrow();
626+
});
627+
622628
it('() : should return an empty object for top-level elements', function () {
623629
var result = $('html').parent();
624630
expect(result).toHaveLength(0);

0 commit comments

Comments
 (0)