diff --git a/src/helpers.ts b/src/helpers.ts index 8dcd591..a0cb504 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -112,8 +112,7 @@ export const convertSecondsToTimeUnit = ( seconds: number, unitNames: { minute: string; hour: string; day: string } ) => { - if (seconds === null || seconds === 0) - return { time: null, unit: unitNames.minute }; + if (seconds === null || seconds === 0) return { time: '', unit: '' }; if (seconds < 3600) return { time: Number((seconds / 60).toFixed(1)), unit: unitNames.minute }; if (seconds < 86400) diff --git a/test/helpers.test.ts b/test/helpers.test.ts index ce7488f..36db1e2 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -43,4 +43,9 @@ describe('#convertSecondsToTimeUnit', () => { }) ).toEqual({ time: 1, unit: 'Days' }); }); + it("it should return { time: '', unit: '' } if seconds passed is 0", () => { + expect( + convertSecondsToTimeUnit(0, { minute: 'm', hour: 'h', day: 'd' }) + ).toEqual({ time: '', unit: '' }); + }); });