Testing
Technical reference for testing tools, coverage targets, custom renderer API, and query priority in the Ledger Wallet monorepo.
Testing Requirements
| Scenario | Requirement |
|---|---|
New features in features/ or mvvm/ | Must include unit and integration tests |
| Bug fixes in new architecture | Must include a regression test covering the use case |
| New components in legacy code | Use new arch patterns to ease future migration |
| Major feature reworks in legacy code | Consider full migration to new architecture with tests (coordinate with Product) |
Testing Tools
| Tool | Purpose | Documentation |
|---|---|---|
| Jest | JavaScript test runner with DOM access via jsdom | Getting Started |
| React Testing Library | Test React components without implementation details | Documentation |
| React Native Testing Library | Test React Native components (for LLM) | Documentation |
| Mock Service Worker (MSW) | API mocking for network requests | Documentation |
Query Priority
When writing tests, follow the query priority recommended by Testing Library:
- React: About Queries
- React Native: How Should I Query
Use ByRole queries when possible. If your component lacks aria attributes,
consider adding them when it makes sense. Otherwise, use other queries
following the priority guide.
Coverage Targets
| Type | Target | Notes |
|---|---|---|
| Features / User Stories | >= 80% | Complex features with multiple conditions |
| Generic Components | >= 90% | Reusable components used in different contexts |
| Helper Functions | 100% | Pure functions like date formatting, number parsing |
| Redux Actions/Reducers | 100% | Well-documented at Redux Testing |
Do not focus solely on coverage scores. Use coverage as a tool to identify untested code paths.
Custom Renderer API
Mobile (ledger-live-mobile)
Import from @tests/test-renderer:
import { render, screen, renderHook } from "@tests/test-renderer";Available Render Functions
| Function | Use Case |
|---|---|
render | Render components with all providers |
renderHook | Test custom hooks in isolation |
renderWithReactQuery | Components needing React Query |
customRenderHookWithLiveAppProvider | Hooks needing Live App context |
Providers Included
Provider(Redux)FirebaseFeatureFlagsProvider(Feature Flags)NavigationContainer(React Navigation routing)CountervaluesProvider/CountervaluesMarketcapBridgedProviderStyleProvider(theming)I18nextProvider(translations)BottomSheetModalProviderQueuedDrawersContextProviderAnalyticsContextProviderQueryClientProvider(when usingrenderWithReactQuery)
Desktop (ledger-live-desktop)
Import from tests/testSetup:
import { render, screen, renderHook, userEvent } from "tests/testSetup";Available Render Functions
| Function | Use Case |
|---|---|
render | Render components with all providers |
renderHook | Test custom hooks in isolation |
renderWithMockedCounterValuesProvider | Components needing countervalues |
renderHookWithLiveAppProvider | Hooks needing Live App context |
Providers Included
QueryClientProvider(React Query)Provider(Redux)FirebaseFeatureFlagsProvider(Feature Flags)MemoryRouter(React Router routing — supportsinitialRouteoption)CountervaluesProvider/CountervaluesMarketcapProviderI18nextProvider(translations)DrawerProviderDialogProviderStyleProvider(theming)ContextMenuWrapper
Modules That Don’t Need Mocking
When using the custom renderer, the following modules are already provided:
| Module | Why No Mock Needed |
|---|---|
react-i18next / useTranslation | I18nextProvider is included with real i18n instance |
react-redux / useSelector / useDispatch | Real Redux Provider with configurable store |
useTheme / Theme hooks | StyleProvider is included |
useFeature / Feature flags | FirebaseFeatureFlagsProvider is included |
| Navigation hooks | NavigationContainer (Mobile) / MemoryRouter (Desktop) |
useAnalytics | AnalyticsContextProvider is included (Mobile) |
Notes
- Always prefer the custom render utilities over raw
@testing-libraryrender - Use
overrideInitialState(Mobile) orinitialState(Desktop) to customize Redux state - Use
initialRouteoption (Desktop only) to set the starting route for navigation tests - The
userobject returned provides realistic user interaction simulation - The
storeobject can be used to verify state changes after actions - Feature flags can be customized via the
getFeaturefunction in the test setup files
Internal Resources
The following internal resources are available to Ledger team members:
- Testing Tools Setup
- Testing Tips and Tricks
- Warnings and Errors Policy
See also
- How to Write Tests — Step-by-step guide for writing tests
- How to Use the Custom Renderer — Practical usage of render functions
- Testing Strategy — Why we test the way we do