From dce5169d126da27c3a180b1bbf904da7b1cf4017 Mon Sep 17 00:00:00 2001 From: Uchenna Elizabeth Date: Tue, 27 Oct 2026 09:12:12 +0100 Subject: [PATCH] test: cover string and numeric timestamp inputs for useRelativeTime useRelativeTime (added in #616) accepts string | number | Date timestamps, but every existing test only exercised Date objects (plus null/undefined/ invalid-string). #616 merged into dev with Closes #597 in its body, but GitHub never auto-closed the issue despite the merge. Adds coverage for an ISO date string and a numeric epoch-ms timestamp, the two accepted input shapes that had no test. Closes #597 --- src/hooks/__tests__/useRelativeTime.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hooks/__tests__/useRelativeTime.test.ts b/src/hooks/__tests__/useRelativeTime.test.ts index 86e4d2a1..40220f23 100644 --- a/src/hooks/__tests__/useRelativeTime.test.ts +++ b/src/hooks/__tests__/useRelativeTime.test.ts @@ -71,6 +71,18 @@ describe('useRelativeTime', () => { expect(result.current).toBe('N/A'); }); + it('accepts an ISO date string timestamp', () => { + const iso = new Date(Date.now() - 30_000).toISOString(); + const { result } = renderHook(() => useRelativeTime(iso)); + expect(result.current).toMatch(/just now/i); + }); + + it('accepts a numeric epoch-ms timestamp', () => { + const epochMs = Date.now() - 2 * 60 * 60 * 1000; + const { result } = renderHook(() => useRelativeTime(epochMs)); + expect(result.current).toMatch(/hour/i); + }); + it('cleans up the interval on unmount', () => { const clearIntervalSpy = vi.spyOn(window, 'clearInterval'); const { unmount } = renderHook(() =>