From c2342be93e0f1ff6c5e6009c7df5e4f0dfd99b0b Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Sat, 2 Jan 2021 15:53:13 +0200 Subject: [PATCH 1/2] parent may fail in functions --- lib/api/traversing.js | 2 +- 1 file changed, 1 insertion(+), 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); } From 190b751bb908d615303960d12cea1b45b9de2b89 Mon Sep 17 00:00:00 2001 From: 5saviahv <5saviahv@users.noreply.github.com> Date: Mon, 4 Jan 2021 15:19:09 +0200 Subject: [PATCH 2/2] added test --- test/api/traversing.js | 6 ++++++ 1 file changed, 6 insertions(+) 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);