Skip to content

Add tests for the ThemeContext system-preference change listener #328

Description

@1nonlypiece

📌 Description

src/context/ThemeContext.tsx subscribes to
matchMedia('(prefers-color-scheme: dark)') and only auto-switches when the
user has not stored an explicit theme. The existing theme tests (per the title
list) cover persistence and attribute sync, but the OS-preference change
listener
and its "respect manual override" guard are easy to regress and
deserve direct coverage.

This issue adds tests for the media-query listener.

🎯 Requirements and Context

  • Mock matchMedia with a controllable change dispatcher.
  • With no stored theme, assert a system change to dark updates the theme.
  • With a stored theme, assert a system change is ignored.
  • Assert the listener is removed on unmount (no leak / no late updates).

🛠️ Suggested Execution

1. Fork the repo and create a branch

git checkout -b test/theme-context-system-listener

2. Implement changes

  • Add src/context/__tests__/ThemeContext.systemListener.test.tsx (or extend
    the existing theme test).
  • Provide a matchMedia mock exposing addEventListener/removeEventListener.

3. Test and commit

  • Run: npm run test
  • Edge cases: stored vs unstored theme, unmount before change, repeated changes.

Example commit message

test: cover ThemeContext system-preference change listener

✅ Guidelines

  • Minimum 95% test coverage on the touched lines.
  • No regressions in theme auto-switching.
  • Keep the diff small and reviewer-friendly.
  • Timeframe: 96 hours.

🏷️ Labels

type-testing · area-frontend · MAYBE REWARDED · GRANTFOX OSS · OFFICIAL CAMPAIGN

💬 Community & Support

  • Join the contributor Discord to coordinate, ask questions, and get unblocked
    fast: https://discord.gg/xvNAvMJf
  • Please introduce yourself in the channel before you start so we can avoid
    duplicate work, pair you with a reviewer, and get your PR merged quickly.
  • Maintainers actively triage this channel and aim for fast, clear, respectful
    reviews — reach out any time you're blocked.

Metadata

Metadata

Assignees

Labels

GRANTFOX OSSGrantFox open-source campaignMAYBE REWARDEDEligible for GrantFox rewardOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programarea-frontendFrontend / UI worktype-testingTests and test coverage

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions