Skip to content

Add unit tests for lib/format-date.ts #326

@NiveditJain

Description

@NiveditJain

lib/format-date.ts exports a single formatDate(date: Date): string helper that wraps Intl.DateTimeFormat to produce strings like "Jan 15, 2024, 3:45 PM". It currently has no unit test even though sibling utilities like format-duration.ts are well-covered.

  1. Create __tests__/lib/format-date.test.ts — copy the structure of __tests__/lib/format-duration.test.ts as a template.
  2. Import: import { formatDate } from "@/lib/format-date";
  3. Add cases for: a fixed UTC date (e.g. new Date(Date.UTC(2024, 0, 15, 15, 45))), the start of a month, midnight, single-digit day, and end of year. Assert against the exact expected string.
  4. Run bun run test:run and confirm all cases pass.

Out of scope: changing format-date.ts itself, or adding locale handling. Just lock in current behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions