From 2f05e0ca42a0300ab879a83370e6ac5ec223af41 Mon Sep 17 00:00:00 2001 From: Maria Zuheros Date: Thu, 27 Aug 2026 09:45:58 +0100 Subject: [PATCH] test(notifications): cover the formatTimestamp helper (#2499) --- .../base/src/utils/timestamp.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 packages/notifications/base/src/utils/timestamp.test.ts diff --git a/packages/notifications/base/src/utils/timestamp.test.ts b/packages/notifications/base/src/utils/timestamp.test.ts new file mode 100644 index 00000000..08a0793f --- /dev/null +++ b/packages/notifications/base/src/utils/timestamp.test.ts @@ -0,0 +1,32 @@ +import { expect } from "@std/expect"; +import { describe, it } from "@std/testing/bdd"; + +import { formatTimestamp } from "./timestamp"; + +describe("formatTimestamp", () => { + it("formats a valid epoch timestamp as an ISO string", () => { + expect(formatTimestamp(1700000000000)).toBe("2023-11-14T22:13:20.000Z"); + }); + + it("formats timestamps before the unix epoch", () => { + expect(formatTimestamp(-1000)).toBe("1969-12-31T23:59:59.000Z"); + }); + + it("returns Unknown for 0, since it is falsy", () => { + expect(formatTimestamp(0)).toBe("Unknown"); + }); + + it("returns Unknown for NaN", () => { + expect(formatTimestamp(Number.NaN)).toBe("Unknown"); + }); + + it("returns Unknown for non finite values", () => { + expect(formatTimestamp(Number.POSITIVE_INFINITY)).toBe("Unknown"); + expect(formatTimestamp(Number.NEGATIVE_INFINITY)).toBe("Unknown"); + }); + + it("returns Unknown when the timestamp is beyond the maximum valid date", () => { + // The largest date JS can represent is 8.64e15 ms; one past it is invalid. + expect(formatTimestamp(8.64e15 + 1)).toBe("Unknown"); + }); +}); -- 2.51.2