component-testing

Writes component tests for React and React Native libraries using Vitest and Jest conventions.

23|5|Updated Apr 3, 2025
One-click install
npx skills add https://github.com/LedgerHQ/lumen --skill component-testing-ledgerhq
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: component-testing
Source: https://github.com/LedgerHQ/lumen/tree/main/.claude/skills/component-testing
Command: npx skills add https://github.com/LedgerHQ/lumen --skill component-testing-ledgerhq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing component tests across a cross-platform design system is error-prone because web and React Native use different test runners, rendering harnesses, and query conventions. This Skill encodes the shared testing philosophy and per-platform rules so tests follow the correct structure, coverage expectations, and runner APIs from the start. ## Core Features & Use Cases - Shared conventions: Explicit test global imports, callback spy assertions, behavior-focused coverage, structured describe/it organization, and a no-snapshot policy. - React web guidance: Vitest plus React Testing Library patterns, accessible queries, fireEvent and userEvent usage, and vi.fn() spies. - React Native guidance: Jest plus React Native Testing Library patterns, mandatory ThemeProvider wrapping, testID queries, and jest.fn() spies. - Use Case: When adding a new Button variant in libs/ui-rnative, load this Skill to generate a Jest test suite wrapped in ThemeProvider that covers rendering, interactions, and the disabled state. ## Quick Start Write tests for the Button component in libs/ui-react following the component-testing conventions.

Frequently Asked Questions about component-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write component tests for React with Vitest and Testing Library?▼

Import describe, it, expect, and vi from vitest plus @testing-library/jest-dom, then render components directly with render from @testing-library/react. Prefer accessible queries like getByRole, use fireEvent or userEvent for interactions, and assert with vi.fn() spies.

How do I test React Native components with Jest and React Native Testing Library?▼

Import globals from @jest/globals and render with @testing-library/react-native, wrapping every render in a ThemeProvider with ledgerLiveThemes. Query via testID or getByRole, use fireEvent.press and fireEvent.changeText for interactions, and jest.fn() for spies.

Vitest vs Jest for testing React components in a monorepo?▼

In this design system, web components in libs/ui-react use Vitest with React Testing Library, while React Native components in libs/ui-rnative use Jest with React Native Testing Library. Mixing runner APIs like vi.fn() in an RN test is flagged as an error.

Why does my React Native component test throw when rendering?▼

React Native components read theme tokens, so rendering without a ThemeProvider wrapper throws. Wrap every render in a TestWrapper that provides ThemeProvider with ledgerLiveThemes, a colorScheme, and a locale.

Should I use snapshot tests for UI components?▼

Snapshot tests are discouraged unless there is a clear, documented reason. The conventions favor behavior-focused tests covering rendering, interactions, controlled state, callbacks, and disabled states instead of toMatchSnapshot assertions.