diff --git a/lib/api/traversing.js b/lib/api/traversing.js index 5db3fa1b01..bd417beac8 100644 --- a/lib/api/traversing.js +++ b/lib/api/traversing.js @@ -86,7 +86,7 @@ exports.parent = function (selector) { } }); - if (arguments.length) { + if (selector) { set = exports.filter.call(set, selector, this); } diff --git a/test/api/traversing.js b/test/api/traversing.js index b0434bf2be..eb8cfe60d0 100644 --- a/test/api/traversing.js +++ b/test/api/traversing.js @@ -598,6 +598,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);