Fix isEmptyArray() logic
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 26 Oct 2022 17:55:55 +0000 (19:55 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 26 Oct 2022 17:55:55 +0000 (19:55 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Utils.ts
test/utils/UtilsTest.ts

index 607843cd380e6932dcdbdc58e65e3564ae4b6b2b..e2afc28a6412631c8d4cecb49d52991c228ccc06 100644 (file)
@@ -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;
index bb919294773ec1ff3fc317719ae46bd33cffaab3..eb1681ce857d7aa0bdd6c1ec4b270030546032b7 100644 (file)
@@ -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()', () => {