From 30e2749175efd5daa751c9640441936bbd203265 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 26 Oct 2022 19:55:55 +0200 Subject: [PATCH] Fix isEmptyArray() logic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Utils.ts | 2 +- test/utils/UtilsTest.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 607843cd..e2afc28a 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -188,7 +188,7 @@ export default class Utils { public static isEmptyArray(object: unknown | unknown[]): boolean { if (!Array.isArray(object)) { - return false; + return true; } if (object.length > 0) { return false; diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index bb919294..eb1681ce 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -99,14 +99,16 @@ describe('Utils test suite', () => { it('Verify isEmptyArray()', () => { expect(Utils.isEmptyArray([])).toBe(true); expect(Utils.isEmptyArray([1, 2])).toBe(false); - expect(Utils.isEmptyArray(null)).toBe(false); - expect(Utils.isEmptyArray(undefined)).toBe(false); - expect(Utils.isEmptyArray('')).toBe(false); - expect(Utils.isEmptyArray('test')).toBe(false); - expect(Utils.isEmptyArray(0)).toBe(false); - expect(Utils.isEmptyArray({})).toBe(false); - expect(Utils.isEmptyArray(new Map())).toBe(false); - expect(Utils.isEmptyArray(new Set())).toBe(false); + expect(Utils.isEmptyArray(null)).toBe(true); + expect(Utils.isEmptyArray(undefined)).toBe(true); + expect(Utils.isEmptyArray('')).toBe(true); + expect(Utils.isEmptyArray('test')).toBe(true); + expect(Utils.isEmptyArray(0)).toBe(true); + expect(Utils.isEmptyArray({})).toBe(true); + expect(Utils.isEmptyArray(new Map())).toBe(true); + expect(Utils.isEmptyArray(new Set())).toBe(true); + expect(Utils.isEmptyArray(new WeakMap())).toBe(true); + expect(Utils.isEmptyArray(new WeakSet())).toBe(true); }); it('Verify isEmptyObject()', () => { -- 2.34.1