Skip to content

[TEST] Add Vitest unit tests for lib/walletAdapter.ts#414

Merged
Samuel1-ona merged 1 commit into
Samuel1-ona:mainfrom
ZuLu0890:test/wallet-adapter-vitest-tests
Jun 1, 2026
Merged

[TEST] Add Vitest unit tests for lib/walletAdapter.ts#414
Samuel1-ona merged 1 commit into
Samuel1-ona:mainfrom
ZuLu0890:test/wallet-adapter-vitest-tests

Conversation

@ZuLu0890
Copy link
Copy Markdown

@ZuLu0890 ZuLu0890 commented Jun 1, 2026

Description
Adds comprehensive Vitest unit tests for lib/walletAdapter.ts, which is a critical integration point between the UI and the Freighter wallet. This file previously had no unit test coverage, meaning bugs could silently break all wallet interactions.

Changes
Created lib/tests/walletAdapter.test.ts with 289 lines of tests covering:

Test Cases Covered
getPublicKey() returns correct address format
Tests successful public key retrieval from Freighter
Validates Stellar address format (G-prefixed, 56 characters)
signTransaction() rejects when wallet is locked
Tests rejection when Freighter returns error (e.g., user rejected, wallet locked)
Tests rejection when no signed XDR is returned
isConnected() returns false when Freighter is not installed
Tests error handling when Freighter extension is not available
Tests browser environment validation
Error cases mapped to user-friendly messages
Verifies all error scenarios return clear, actionable error messages
Tests mapping of technical errors to user-friendly text
Additional Test Coverage
Session Management: getStoredWalletSession(), setStoredWalletSession(), clearStoredWalletSession()
Active Adapter: getActiveWalletAdapter() with Freighter provider
Connection Flow: connectWalletProvider() with Freighter
Edge Cases: Window undefined scenarios, localStorage parsing errors, invalid session data
Implementation Details
Uses vi.mock for @stellar/freighter-api module mocking as specified in the issue
Follows existing test patterns from walletAdapterXBull.test.ts
Uses Vitest with jsdom environment
Mocks localStorage and window objects appropriately
closes #339

@Samuel1-ona Samuel1-ona merged commit 74dacbd into Samuel1-ona:main Jun 1, 2026
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.

[TEST] Add Vitest unit tests for lib/walletAdapter.ts

2 participants