Skip to content

Add unit tests for useCopyToClipboard hook #211

Description

@aadorian

Description

The useCopyToClipboard hook in hooks/copy-to-clipboard.ts handles clipboard writes and a 2-second "copied" feedback state, but has no tests.

Difficulty

Easy

Skills

Jest, React Testing Library (renderHook)

Relevant files

  • hooks/copy-to-clipboard.ts
  • hooks/__tests__/copy-to-clipboard.test.ts (create)

Tasks

  • Create hooks/__tests__/copy-to-clipboard.test.ts
  • Mock navigator.clipboard.writeText
  • Test successful copy sets copied: true, then resets after timeout
  • Test clipboard failure returns false and does not set copied

Acceptance Criteria

  • All tests pass with npm test
  • Clipboard API is mocked (no real clipboard access in CI)
  • Use fake timers for the 2s reset behavior

Getting started

  1. Comment on this issue to get assigned
  2. Fork the repo and create a branch: test/copy-to-clipboard
  3. Run npm ci && npm test before opening a PR

Activity

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions