From 43592d6fa47f7396216196a524a4bcbef976598c Mon Sep 17 00:00:00 2001 From: 5saviahv <49443574+5saviahv@users.noreply.github.com> Date: Mon, 4 Jan 2021 15:24:10 +0200 Subject: [PATCH] fix(traversing): parent() may fail in functions (#1637) --- lib/api/traversing.js | 2 +- test/api/traversing.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 d8e8e40c7b..6b475df1ee 100644 --- a/test/api/traversing.js +++ b/test/api/traversing.js @@ -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);