Skip to content

test(csv): add unit tests for toCsv escaping (comma, quote, newline) #196

Closed

Description

@gkhngyk

Summary

Add unit tests for the CSV serializer in
web/src/lib/csv.ts.
It's a small, pure function with clear escaping rules — an ideal first test
suite.

⚠️ Blocked by #195 — this needs the Vitest setup from #195 to be merged
first. Please don't start until the test runner exists, otherwise there's
nothing to run the tests with.

What to do

Add web/src/lib/csv.test.ts covering toCsv (and its escape behavior via
the public output). Suggested cases:

  • Plain values pass through unquoted (e.g. hello → hello).
  • Comma in a value triggers quoting (e.g. a,b → "a,b").
  • Double quote in a value is doubled and the field is quoted
    (e.g. she said "hi" → "she said ""hi""").
  • Newline in a value triggers quoting (e.g. line1\nline2 → "line1\nline2").
  • null and undefined become empty strings.
  • Header row is emitted first, joined by commas.
  • Column order follows the headers array, and a missing key in a row
    produces an empty field.
  • Multiple rows are joined by \n.

Acceptance

  • cd web && yarn test runs the new suite and it passes.
  • Cases above are all covered.
  • No changes to csv.ts itself — this is test-only. (If a genuine bug is found
    while testing, note it in a separate issue rather than changing behavior here.)

Activity

  1. added
    good first issue
    on Jun 8, 2026
  2. gkhngyk commented on Jun 8, 2026

    @gkhngyk
    ContributorAuthor

    Part of the test-infrastructure epic #125 (item 4). Blocked by #195.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions