From 968fa52958f40c69c65c7a2fdebadd3823829098 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 15 Jul 2020 09:04:36 -0400 Subject: [PATCH] fix test not running Signed-off-by: Sebastian Malton --- src/renderer/utils/formatDuration.ts | 6 +++++- .../formatDuration.test.ts => formatDuration_spec.ts} | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) rename src/renderer/utils/{__tests__/formatDuration.test.ts => formatDuration_spec.ts} (89%) diff --git a/src/renderer/utils/formatDuration.ts b/src/renderer/utils/formatDuration.ts index 1731e1c5cd..84f90731b5 100644 --- a/src/renderer/utils/formatDuration.ts +++ b/src/renderer/utils/formatDuration.ts @@ -23,8 +23,12 @@ export function formatDuration(timeValue: number, compact: boolean) { .filter(([_dur, suf], i) => i === 0 || suf !== "s") // remove seconds, unless it is the only one .map(([dur, suf]) => dur + suf); + if (meaningfulValues.length === 0) { + return "0s"; + } + if (compact) { - return meaningfulValues[0] || "0s"; + return meaningfulValues[0]; } return meaningfulValues.join(" "); diff --git a/src/renderer/utils/__tests__/formatDuration.test.ts b/src/renderer/utils/formatDuration_spec.ts similarity index 89% rename from src/renderer/utils/__tests__/formatDuration.test.ts rename to src/renderer/utils/formatDuration_spec.ts index 13086c099d..4a3bd9dd3d 100644 --- a/src/renderer/utils/__tests__/formatDuration.test.ts +++ b/src/renderer/utils/formatDuration_spec.ts @@ -1,4 +1,4 @@ -import { formatDuration } from "../formatDuration"; +import { formatDuration } from "./formatDuration"; const second = 1000; const minute = 60 * second; @@ -45,9 +45,7 @@ describe("human format durations", () => { }); test("zero duration should output something", () => { - const zero = formatDuration(0, false); - - expect(zero).not.toHaveLength(0); - expect(zero).toBe("0s"); + expect(formatDuration(0, false)).toBe("0s"); + expect(formatDuration(0, true)).toBe("0s"); }); });