Skip to content

Add RTL tests for the useWallet hook covering Freighter connect, disconnect, and error paths #590

@1nonlypiece

Description

@1nonlypiece

📌 Description

src/hooks/useWallet.ts manages Freighter connection state (connect,
disconnect, auto-detect on mount, error handling) but has no test coverage.
This hook gates all wallet-dependent flows, so its connect/disconnect/error
transitions must be verified.

This issue adds tests for useWallet, mocking @stellar/freighter-api.

Goal: prove useWallet correctly reflects connected/disconnected/error
state across mount, connect, disconnect, and Freighter failures.

🎯 Requirements and Context

  • Mock getAddress from @stellar/freighter-api.
  • Cover: auto-detect on mount when already connected; connect populating
    address/connected; result.error path setting error and clearing
    connection; thrown-exception path; disconnect resetting all state.
  • Use @testing-library/react renderHook.

🛠️ Suggested Execution

1. Create a branch

git checkout -b feature/use-wallet-tests

2. Implement changes

  • Add src/hooks/__tests__/useWallet.test.ts.
  • Mock the Freighter API per scenario.

3. Test and commit

  • Run npm test.
  • Edge cases: getAddress returns { error }, returns no address, throws,
    resolves with an address, repeated connect calls.

Example commit message

test: cover useWallet connect/disconnect/error paths

✅ Guidelines

  • Minimum 95% test coverage on the hook.
  • Clear, descriptive test names.
  • Timeframe: 96 hours.

🏷️ Labels

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

💬 Community & Support

  • Join the CommitLabs contributor Discord: https://discord.gg/WV7tdYkJk
  • Introduce yourself before starting to avoid duplicate work.
  • Maintainers triage actively and review fast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions