From 4e276cc7fe5ba6090afa4cb7b45b0f0885d0f149 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 26 Jan 2023 00:17:18 +0100 Subject: [PATCH] Revert incorrect isEmptyString() semantic change 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, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 0952be9b..6557a588 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -193,7 +193,7 @@ export default class Utils { } public static isEmptyString(value: unknown): boolean { - return Utils.isString(value) ? (value as string).trim().length === 0 : true; + return Utils.isString(value) && (value as string).trim().length === 0; } public static isUndefined(value: unknown): boolean { diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index a3166aed..21d5d137 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -161,15 +161,15 @@ describe('Utils test suite', () => { expect(Utils.isEmptyString('test')).toBe(false); expect(Utils.isEmptyString(' test')).toBe(false); expect(Utils.isEmptyString('test ')).toBe(false); - expect(Utils.isEmptyString(null)).toBe(true); - expect(Utils.isEmptyString(undefined)).toBe(true); - expect(Utils.isEmptyString(0)).toBe(true); - expect(Utils.isEmptyString({})).toBe(true); - expect(Utils.isEmptyString([])).toBe(true); - expect(Utils.isEmptyString(new Map())).toBe(true); - expect(Utils.isEmptyString(new Set())).toBe(true); - expect(Utils.isEmptyString(new WeakMap())).toBe(true); - expect(Utils.isEmptyString(new WeakSet())).toBe(true); + expect(Utils.isEmptyString(null)).toBe(false); + expect(Utils.isEmptyString(undefined)).toBe(false); + expect(Utils.isEmptyString(0)).toBe(false); + expect(Utils.isEmptyString({})).toBe(false); + expect(Utils.isEmptyString([])).toBe(false); + expect(Utils.isEmptyString(new Map())).toBe(false); + expect(Utils.isEmptyString(new Set())).toBe(false); + expect(Utils.isEmptyString(new WeakMap())).toBe(false); + expect(Utils.isEmptyString(new WeakSet())).toBe(false); }); it('Verify isUndefined()', () => { -- 2.34.1