Skip to content

Add tests for slugify and assignSlugs (src/lib/placement.ts has no test file) #885

Description

@TortoiseWolfe

The task

src/lib/placement.ts exports slugify, assignSlugs and applyOverrides, and has no test
file
. Add one.

Why this is a good first issue

slugify is the classic pure function — a string goes in, a URL-safe string comes out — and
assignSlugs builds on it. You can read the whole module in a couple of minutes and it needs no
setup.

Where the test goes

src/lib/placement.test.ts, beside the source. Read the implementation first and write tests for
what it actually does, not what you assume a slugifier does — the interesting cases are where
implementations differ.

Acceptance criteria

  • A test file exists at src/lib/placement.test.ts
  • slugify covered for: spaces, mixed case, punctuation, leading/trailing whitespace, and a
    string that is already a valid slug (it should come back unchanged)
  • assignSlugs covered for the case that actually matters: two inputs that slugify to the
    same string.
    Whatever it does — suffix, dedupe, overwrite — pin it, because that is the
    behaviour someone will accidentally change later
  • applyOverrides has at least one case
  • docker compose exec scripthammer pnpm test --run src/lib/placement.test.ts passes

The one thing that matters here

Read the code before writing the test, and if slugify does something you find surprising, do
not "fix" it in the same PR
. Pin the current behaviour and say in the PR description that you
found it surprising. Changing behaviour and adding its first test at the same time means nobody
can tell which of the two broke something later.

And break it on purpose before opening the PR — confirm your test goes red, then undo. Say which
mutation you tried; a test that cannot fail is the most common defect here (#396).

Getting set up

docker compose up -d
docker compose exec scripthammer pnpm test --run src/lib/placement.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions