diff --git a/packages/utils/src/utils.spec.ts b/packages/utils/src/utils.spec.ts index ae786865f..46d81a8b5 100644 --- a/packages/utils/src/utils.spec.ts +++ b/packages/utils/src/utils.spec.ts @@ -10,6 +10,7 @@ import { hasData, isEmptyObject, isNumber, + isObject, isObjectEmpty, parseBoolean, removeAccentFromText, @@ -112,6 +113,40 @@ describe('Service/Utilies', () => { }); }); + describe('isObject method', () => { + it('should return false when input is undefined', () => { + expect(isObject(undefined)).toBeFalse(); + }); + + it('should return false when input is null', () => { + expect(isObject(null)).toBeFalse(); + }); + + it('should return false when input is empty string', () => { + expect(isObject('')).toBeFalse(); + }); + + it('should return false when input is a string', () => { + expect(isObject('some text')).toBeFalse(); + }); + + it('should return false when input is an empty array', () => { + expect(isObject([])).toBeFalse(); + }); + + it('should return false when input a Date', () => { + expect(isObject(new Date())).toBeFalse(); + }); + + it('should return true when input is an empty object', () => { + expect(isObject({})).toBeTrue(); + }); + + it('should return true when input is an object', () => { + expect(isObject({ msg: 'hello workd' })).toBeTrue(); + }); + }); + describe('isObjectEmpty method', () => { it('should return True when input is undefined', () => { const result = isObjectEmpty(undefined); diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index e75e14c1f..de5631330 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -167,7 +167,7 @@ export function isEmptyObject(obj: any): boolean { * @returns {boolean} */ export function isObject(item: any) { - return (item && typeof item === 'object' && !Array.isArray(item)); + return item !== null && typeof item === 'object' && !Array.isArray(item) && !(item instanceof Date); } /**