Testing

Technical reference for testing tools, coverage targets, custom renderer API, and query priority in the Ledger Wallet monorepo.


Testing Requirements

ScenarioRequirement
New features in features/ or mvvm/Must include unit and integration tests
Bug fixes in new architectureMust include a regression test covering the use case
New components in legacy codeUse new arch patterns to ease future migration
Major feature reworks in legacy codeConsider full migration to new architecture with tests (coordinate with Product)

Testing Tools

ToolPurposeDocumentation
JestJavaScript test runner with DOM access via jsdomGetting Started
React Testing LibraryTest React components without implementation detailsDocumentation
React Native Testing LibraryTest React Native components (for LLM)Documentation
Mock Service Worker (MSW)API mocking for network requestsDocumentation

Query Priority

When writing tests, follow the query priority recommended by Testing Library:

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

TypeTargetNotes
Features / User Stories>= 80%Complex features with multiple conditions
Generic Components>= 90%Reusable components used in different contexts
Helper Functions100%Pure functions like date formatting, number parsing
Redux Actions/Reducers100%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

FunctionUse Case
renderRender components with all providers
renderHookTest custom hooks in isolation
renderWithReactQueryComponents needing React Query
customRenderHookWithLiveAppProviderHooks needing Live App context

Providers Included

  • Provider (Redux)
  • FirebaseFeatureFlagsProvider (Feature Flags)
  • NavigationContainer (React Navigation routing)
  • CountervaluesProvider / CountervaluesMarketcapBridgedProvider
  • StyleProvider (theming)
  • I18nextProvider (translations)
  • BottomSheetModalProvider
  • QueuedDrawersContextProvider
  • AnalyticsContextProvider
  • QueryClientProvider (when using renderWithReactQuery)

Desktop (ledger-live-desktop)

Import from tests/testSetup:

import { render, screen, renderHook, userEvent } from "tests/testSetup";

Available Render Functions

FunctionUse Case
renderRender components with all providers
renderHookTest custom hooks in isolation
renderWithMockedCounterValuesProviderComponents needing countervalues
renderHookWithLiveAppProviderHooks needing Live App context

Providers Included

  • QueryClientProvider (React Query)
  • Provider (Redux)
  • FirebaseFeatureFlagsProvider (Feature Flags)
  • MemoryRouter (React Router routing — supports initialRoute option)
  • CountervaluesProvider / CountervaluesMarketcapProvider
  • I18nextProvider (translations)
  • DrawerProvider
  • DialogProvider
  • StyleProvider (theming)
  • ContextMenuWrapper

Modules That Don’t Need Mocking

When using the custom renderer, the following modules are already provided:

ModuleWhy No Mock Needed
react-i18next / useTranslationI18nextProvider is included with real i18n instance
react-redux / useSelector / useDispatchReal Redux Provider with configurable store
useTheme / Theme hooksStyleProvider is included
useFeature / Feature flagsFirebaseFeatureFlagsProvider is included
Navigation hooksNavigationContainer (Mobile) / MemoryRouter (Desktop)
useAnalyticsAnalyticsContextProvider is included (Mobile)

Notes

  • Always prefer the custom render utilities over raw @testing-library render
  • Use overrideInitialState (Mobile) or initialState (Desktop) to customize Redux state
  • Use initialRoute option (Desktop only) to set the starting route for navigation tests
  • The user object returned provides realistic user interaction simulation
  • The store object can be used to verify state changes after actions
  • Feature flags can be customized via the getFeature function 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

Ledger
Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Stax, Ledger Flex, Ledger Nano, Ledger Nano S, Ledger OS, Ledger Wallet, [LEDGER] (logo), [L] (logo) are trademarks owned by Ledger SAS.