From f515091ac58f309106dd06a86e9c6a011f90623d Mon Sep 17 00:00:00 2001 From: Avior Date: Thu, 18 Nov 2021 17:38:19 +0100 Subject: [PATCH] Updated tests and documentation to be more clear Signed-off-by: Avior --- packages/object-util/__tests__/index.test.ts | 29 ++++++++++++++++++++ packages/object-util/src/ObjectUtil.ts | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/object-util/__tests__/index.test.ts b/packages/object-util/__tests__/index.test.ts index 46b32e1..cd60265 100644 --- a/packages/object-util/__tests__/index.test.ts +++ b/packages/object-util/__tests__/index.test.ts @@ -36,6 +36,35 @@ describe('Object Loop Tests', () => { throw "it should not come here" } }) + + }) + + it('Should return false', () => { + const obj = { + pouet: true + } + expect(objectLoop(obj, () => { + return false + })).toBe(false) + // TO BE EXPECTED in MAJOR change + // expect(objectLoop(obj, () => { + // return undefined + // })).toBe(false) + + }) + + it('Should return true', () => { + const obj = { + pouet: true + } + expect(objectLoop(obj, () => { + return true + })).toBe(true) + // TO BE EXPECTED until major change + expect(objectLoop(obj, () => { + return undefined + })).toBe(true) + }) }) diff --git a/packages/object-util/src/ObjectUtil.ts b/packages/object-util/src/ObjectUtil.ts index 30833fc..e25acfb 100644 --- a/packages/object-util/src/ObjectUtil.ts +++ b/packages/object-util/src/ObjectUtil.ts @@ -20,7 +20,7 @@ export function objectMap( /** * Loop through the object * @param obj the object to loop through - * @param fn the function to run for each childs + * @param fn the function to run for each childs if the function return `false` it will stop */ export function objectLoop( obj: Record,