From 3446b0556ceb818650e440fd2cff73b8f89d54c7 Mon Sep 17 00:00:00 2001 From: adarsh tiwari Date: Thu, 21 May 2026 20:19:50 +0530 Subject: [PATCH] test: add unit tests for lib/format-date.ts Co-Authored-By: Claude Opus 4.5 --- __tests__/lib/format-date.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 __tests__/lib/format-date.test.ts diff --git a/__tests__/lib/format-date.test.ts b/__tests__/lib/format-date.test.ts new file mode 100644 index 0000000..ae81113 --- /dev/null +++ b/__tests__/lib/format-date.test.ts @@ -0,0 +1,29 @@ +import { describe, it, expect } from "vitest"; +import { formatDate } from "@/lib/format-date"; + +describe("formatDate", () => { + it("formats a standard date: Jan 15, 2024, 3:45 PM", () => { + const date = new Date(2024, 0, 15, 15, 45); + expect(formatDate(date)).toBe("Jan 15, 2024, 3:45 PM"); + }); + + it("formats start of month: Mar 1, 2024, 9:30 AM", () => { + const date = new Date(2024, 2, 1, 9, 30); + expect(formatDate(date)).toBe("Mar 1, 2024, 9:30 AM"); + }); + + it("formats midnight: Feb 10, 2024, 12:00 AM", () => { + const date = new Date(2024, 1, 10, 0, 0); + expect(formatDate(date)).toBe("Feb 10, 2024, 12:00 AM"); + }); + + it("formats single-digit day: Jul 5, 2024, 2:15 PM", () => { + const date = new Date(2024, 6, 5, 14, 15); + expect(formatDate(date)).toBe("Jul 5, 2024, 2:15 PM"); + }); + + it("formats end of year: Dec 31, 2024, 11:59 PM", () => { + const date = new Date(2024, 11, 31, 23, 59); + expect(formatDate(date)).toBe("Dec 31, 2024, 11:59 PM"); + }); +});