From: Jérôme Benoit Date: Wed, 26 Oct 2022 17:55:55 +0000 (+0200) Subject: Fix isEmptyArray() logic X-Git-Tag: v1.1.86~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=30e2749175efd5daa751c9640441936bbd203265;p=e-mobility-charging-stations-simulator.git Fix isEmptyArray() logic Signed-off-by: Jérôme Benoit --- 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()', () => {