Skip to main content

Testing

This guide covers testing React components that use the Privacy Boost SDK.

Mock the Hooks, Not the SDK

The hooks subscribe to the SDK’s own stores (sdk.stores), which are internal and not something a test can stand in for. A hand-built object passed to <PrivacyBoostProvider sdk={...}> makes every hook throw on its first render. For unit tests, mock the hooks your components call. Exercise the real SDK in integration tests against a test deployment. The examples use Jest and React Testing Library; with Vitest, swap jest for vi.

Testing Components

Testing useAuth

Build the result from state, which is what components should render from. A returning user is signed in with locked: true.

Testing useVault

To assert on a specific error code, reject with a real PrivacyBoostError: new PrivacyBoostError(ErrorCodes.TRANSACTION_REJECTED, 'declined').

Testing useBalances

Testing Hooks

Custom Hook Testing

A custom hook built on the SDK hooks, such as useDepositFlow from Custom Hooks, is tested the same way: mock what it calls.

Mocking window.ethereum

signInWithWalletAdapter builds its adapter from window.ethereum. When a test renders the real useAuth against a mocked wallet, stub the provider:

Next Steps