Component testing

From LedgerHQ/lumen · View interactive version

Component testing is an AI agent skill from the GitHub repository LedgerHQ/lumen. Use when writing or editing component tests in libs/ui-react or libs/ui-rnative — shared structure and coverage conventions, plus the per-platform runner: Vitest + React Testing Library on web, Jest + React Native Testing Library on RN. Load this before writing tests.

How to use this skill

Skill file

Component testing

Same testing philosophy on both platforms; the runner and rendering harness

differ. Read the shared conventions, then the section for the lib you're in

(derive it from the path — see the Libraries table in AGENTS.md).

Shared conventions (both platforms)

toHaveBeenCalledTimes, toHaveBeenCalledWith, not.toHaveBeenCalled.

controlled state, callbacks, and the disabled state.

it('should …') cases for simple components; nest describe blocks by concern

(Rendering, Appearances, Sizes, Interactions, States, Styling) for

richer components, and it.each([...]) for variant/size matrices.

statements, functions and branches, with every source file counted. Check

locally with npx nx test <project> --coverage. The threshold lives in each

lib's runner config — a new lib copies the coverage block from a sibling.

React web (`libs/ui-react`)

Runner: Vitest + React Testing Library.

import '@testing-library/jest-dom';.

render directly with render(<Component />), no wrapper.

data-testid only when nothing accessible applies.

@testing-library/user-event for typing / keyboard / focus.

React Native (`libs/ui-rnative`)

Runner: Jest + React Native Testing Library.

@testing-library/react-native. **Every render must be wrapped in a

ThemeProvider** — components read theme tokens, so an unwrapped render

throws. Use a small TestWrapper:

import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
import { render, fireEvent, waitFor } from '@testing-library/react-native';
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';

const TestWrapper = ({ children }: { children: React.ReactNode }) => (
  <ThemeProvider themes={ledgerLiveThemes} colorScheme='dark' locale='en'>
    {children}
  </ThemeProvider>
);

getByRole for semantic elements like switches.

low-level fireEvent(element, '<eventName>') form for non-press events

(longPress, onError). Use waitFor for state that updates after an

interaction.

Review checks

Rules verifiable from a diff.

| Check | Applies to | Detect | Skip |

| --- | --- | --- | --- |

| Wrong runner API for the lib | both | jest.fn()/@jest/globals in a ui-react test; vi.fn()/vitest in a ui-rnative test | — |

| RN render not wrapped in ThemeProvider | rnative | render(<…/>) without a themed wrapper | — |

| data-testid/testID used where an accessible query fits | both | getByTestId on a role-bearing element | root nodes with no accessible role |

| Snapshot test with no justification | both | toMatchSnapshot() | intentional, commented snapshots |

| Missing coverage of the disabled/controlled path on an interactive component | both | no test touching disabled/controlled state | non-interactive components |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.