Skip to content

feat(#93): Add comprehensive test suite for WalletContext connect, disconnect, and error states#114

Merged
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
OZILSOLAR:feat/issue-93-wallet-context-tests
Jun 19, 2026
Merged

feat(#93): Add comprehensive test suite for WalletContext connect, disconnect, and error states#114
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
OZILSOLAR:feat/issue-93-wallet-context-tests

Conversation

@OZILSOLAR

Copy link
Copy Markdown
Contributor

PR Description

Overview

This PR implements comprehensive test coverage for WalletContext as specified in issue #93, ensuring wallet state management is robust and reliable across connect, disconnect, and error scenarios.

Changes Implemented

New Test File

  • src/contexts/__tests__/WalletContext.test.tsx (149 lines)
    • Comprehensive test suite for WalletContext provider state machine
    • Uses @testing-library/react for component testing
    • Implements fake timers to test async connection flow

Test Coverage

1. connect() State Management

  • ✅ Verifies isConnecting is set to true immediately upon connection attempt
  • ✅ Confirms connection resolves to mocked wallet address after simulated 1000ms delay
  • ✅ Validates isConnecting returns to false after successful connection

2. disconnect() Functionality

  • ✅ Confirms address is cleared when disconnect() is invoked
  • ✅ Validates state properly transitions after disconnect

3. Error State Reset

  • ✅ Ensures error state is reset to null when a new connect() is called
  • ✅ Prevents stale error messages from interfering with subsequent connections

4. Provider Guard

  • ✅ Tests that calling useWallet() outside WalletProvider throws documented error: "useWallet must be used within a WalletProvider"
  • ✅ Verifies error boundary behavior

Technical Details

  • Uses Jest fake timers (useFakeTimers()) to control async timing
  • Implements test consumer component WalletConsumer to access context values
  • Unmocks global WalletContext mock to test real provider behavior
  • Uses data-testid for reliable element queries
  • Properly cleans up timers after each test

Verification

  • ✅ All 4 tests pass
  • ✅ Build succeeds without errors
  • ✅ ESLint passes with no warnings or errors
  • ✅ No breaking changes to existing code

Testing

  • Run tests: npm test -- src/contexts/__tests__/WalletContext.test.tsx
  • All tests passing: 4/4 ✓

Closes #93

…, and error states

- Test that connect() sets isConnecting true and resolves to address
- Test that disconnect() clears the address
- Test that error is reset on new connect()
- Test that useWallet() throws error when called outside WalletProvider
- Use fake timers to simulate connection delay
- Use test consumer component and @testing-library/react
@mikewheeleer

Copy link
Copy Markdown
Contributor

really thorough suite for the wallet connect/disconnect/error states, appreciate the care here. lgtm 🙌

@mikewheeleer mikewheeleer merged commit c1ddc84 into Talenttrust:main Jun 19, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for WalletContext connect, disconnect, and error states

2 participants