This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the React Native Testing Library (RNTL) - a comprehensive testing solution for React Native applications that provides React Native runtime simulation on top of react-test-renderer. The library encourages better testing practices by focusing on testing behavior rather than implementation details.
yarn test- Run all testsyarn test:ci- Run tests with CI optimizations (maxWorkers=2)yarn test:ci:coverage- Run tests with coverage reporting
yarn build- Full build process (clean, build JS, build types, copy flow types)yarn build:js- Build JavaScript using Babelyarn build:ts- Build TypeScript declarationsyarn clean- Clean build directory
yarn typecheck- Run TypeScript compileryarn lint- Run ESLint with cachingyarn validate- Run lint + typecheck + test (pre-commit validation)
To test a specific file: yarn test path/to/test.test.tsx
src/index.ts- Main entry point that sets up auto-cleanup and extends Jest matcherssrc/pure.ts- Pure exports without auto-cleanup for advanced use casessrc/render.tsx- Core rendering functionality usingreact-test-renderersrc/screen.ts- Global screen object providing access to rendered components
src/queries/- Query functions for finding elements (byText, byRole, byTestId, etc.)src/matchers/- Jest matchers for assertions (toBeVisible, toHaveTextContent, etc.)src/user-event/- User interaction simulation (press, type, scroll, etc.)src/helpers/- Utility functions for component tree traversal and debuggingsrc/fire-event.ts- Low-level event firing utilities
The library provides three query variants for each selector:
get*- Throws if not found (for assertions)query*- Returns null if not found (for conditional logic)find*- Returns Promise, waits for element (for async operations)
- User Events (
src/user-event/) - High-level, realistic user interactions - Fire Events (
src/fire-event.ts) - Low-level, direct event dispatching
- Main Jest config:
jest.config.js - Setup file:
jest-setup.ts - Uses React Native preset with custom transform ignore patterns
- Main config:
tsconfig.json(development) - Release config:
tsconfig.release.json(for builds) - Strict mode enabled with ES2022 target
- Config:
eslint.config.mjs - Uses Callstack config + TypeScript strict rules
- Custom rules for import sorting and test files
import { render, screen, userEvent } from '@testing-library/react-native';
test('component behavior', async () => {
const user = userEvent.setup();
render(<MyComponent />);
await user.press(screen.getByRole('button'));
expect(screen.getByText('Expected text')).toBeOnTheScreen();
});Use findBy* queries or waitFor for async operations:
const element = await screen.findByText('Async content');
await waitFor(() => expect(mockFn).toHaveBeenCalled());- Working with Examples: Test changes in
examples/directory - Commit Messages: Follow conventional commits (feat:, fix:, docs:, test:, chore:, refactor:, BREAKING:)
- Pre-commit: Hooks verify linting, type checking, and tests pass
- Pull Requests: Run
yarn validatebefore submitting
The build creates:
build/- Compiled JavaScript and TypeScript declarationsmatchers.js- Jest matchers for separate importpure.js- Pure version without auto-cleanupdont-cleanup-after-each.js- Version without auto-cleanup
- Main exports: Full library with auto-cleanup
- Pure exports: Library without auto-cleanup (
/pure) - Matcher exports: Jest matchers only (
/matchers) - No cleanup: Disable auto-cleanup (
/dont-cleanup-after-each)
- Uses
react-test-rendererfor component rendering - Fake timers recommended for user events
- String validation available for text rendering checks
- Supports both concurrent and legacy React rendering modes