Write unit and integration tests for Ledger Wallet apps.
Use for Jest tests (Desktop/Mobile), MSW handlers and testing best practices.
Applies to "*.test.*", "*.spec.*", "**/tests/**", "**/__tests__/**", "**/__integrations__/**", "**/jest-setup*"
Write unit and integration tests for Ledger Wallet apps.
Use for Jest tests (Desktop/Mobile), MSW handlers and testing best practices.
Applies to "*.test.*", "*.spec.*", "**/tests/**", "**/__tests__/**", "**/__integrations__/**", "**/jest-setup*"
toBeVisible() over toBeInTheDocument() — Always. toBeInTheDocument only checks DOM presence; elements can be hidden. Use toBeInTheDocument only when testing explicitly hidden elements.
Search before you create — Before writing any mock, fixture, or helper, rg the codebase. If it exists, import it. If your new mock is reusable (2+ files), put it in a shared location.
Mock external deps only — Never mock child components. Test integration.
One behavior per test — Name: it("should <behavior> when <condition>").
Feature flags via store, never mocked — Use overriddenFeatureFlags in initialState.settings.
Use existing factories — genAccount() from @ledgerhq/ledger-wallet-framework/mocks/account, getCryptoCurrencyById() from @ledgerhq/live-common/currencies. Never recreate account/currency data from scratch.
Quick Reference
pnpm test:jest "filename"# Run specific file
pnpm test:jest # Run all tests
pnpm test:jest --coverage # Coverage report# Coin modules (libs/coin-modules)
pnpm coin:<name> test# Unit tests
pnpm coin:<name> test"filename"# Specific file
pnpm coin:<name> test-integ # Integration tests (slow)
# Run BEFORE writing new mocks
rg "yourMockName|yourHelper" tests/ __tests__/ src/ libs/ --type ts
New reusable mocks go in tests/mocks/, new handlers in tests/handlers/, new fixtures in tests/handlers/fixtures/.
Mock Anti-Patterns
These cause flaky tests and mock cannibalization when running with parallel workers (--maxWorkers=50%).
Duplicate mocks — Don't jest.mock("module") in a test file when it's already mocked in jest-setup (apps/ledger-live-mobile/__tests__/jest-setup.js or apps/ledger-live-desktop/tests/jestSetup.js). Use jest.mocked(module.export).mockReturnValue(...) in beforeEach instead.
Hooks at describe load time — Never call renderHook(...) or access .result.current at the top level of a describe block. Move into beforeEach or inside each test — calling hooks outside of test callbacks crashes Jest parallel workers.
jest.restoreAllMocks() — Never use this; it restores global mocks from jest-setup and breaks other tests. Use jest.clearAllMocks() or mock.mockRestore() for specific spies only.
Wrong beforeEach order — Call jest.clearAllMocks()beforemockReturnValue() or other mock configuration — not after (calling clear after wipes the setup).
Workflow
1. Search for existing mocks → 2. Write test → 3. Run test → 4. Fix if fail → 5. Next file
Start with the simplest units (utils, hooks), then work up to components with side effects (API, navigation). This order catches foundational bugs early and builds confidence incrementally.