This document provides context for the any code assistant to understand the @testing-library/react-native project.
@testing-library/react-native (RNTL) provides a set of utilities for testing React Native components. It is designed to facilitate writing tests that resemble how users interact with the application, avoiding implementation details.
- Core Principle: "The more your tests resemble the way your software is used, the more confidence they can give you."
- Tech Stack: TypeScript, React Native, Jest.
- Architecture: The library simulates the React Native runtime on top of
test-renderer.
- Small API surface
- Expose all features of the underlying platform (react, react-reconciler) for Testing Libraries to use
- Render host elements only, yet provide escape hatches to fibers when needed
The project uses yarn for dependency management and script execution.
- Installation:
yarn install - Run Tests:
yarn test(Runs Jest) - Run Tests (CI):
yarn test:ci(Runs Jest with worker limits) - Lint Code:
yarn lint(Runs ESLint onsrc) - Type Check:
yarn typecheck(Runs TypeScript compiler) - Format Check:
yarn prettier - Validate All:
yarn validate(Runs Prettier, ESLint, Typecheck, and Tests in sequence) - Build Project:
yarn build(Cleans, builds JS with Babel, and builds TS types)
-
Code Style:
- Linting: ESLint is configured with
@callstack/eslint-configandtypescript-eslint. It enforces strict rules, includingno-consoleand consistent type imports. - Formatting: Prettier is used for code formatting (single quotes, trailing commas).
- Imports: Sorted using
eslint-plugin-simple-import-sort.
- Linting: ESLint is configured with
-
Testing:
- Framework: Jest with
react-nativepreset. - Location: Tests are located within
src, typically co-located in__tests__directories. - Setup:
jest-setup.tsconfigures the test environment.src/index.tsautomatically configures cleanup after each test unless skipped. - Coverage: Collected from
src, excluding tests. - Organization: Use
describeto group test by theme. Avoid putting all tests in the samedescribeblock. Avoiddescribenesting. Avoiddescribewith only single test, make that test top-level. Preferetestoverit.
- Framework: Jest with
-
Commits & Releases:
- Commits: Follow the Conventional Commits specification (e.g.,
fix:,feat:,chore:). This is enforced and used for changelog generation. - Releases: Managed via
release-it.
- Commits: Follow the Conventional Commits specification (e.g.,
-
File Structure:
src/: Source code.src/pure.ts: Core logic without side effects (no auto-cleanup).src/index.ts: Main entry point, re-exportspureand adds side effects (auto-cleanup).examples/: Example React Native applications using the library.website/: Documentation website.
-
Prefer regenerating Expo example apps in a temporary directory and then copying the fresh scaffold into place, instead of mutating the existing app in place.
-
Before replacing an example app, move the current app directory to
/tmpso repo-specific code, tests, assets, and configs can be restored selectively. -
After copying a freshly generated app into
examples/, remove the generated.gitdirectory and generatednode_modules, then reinstall from inside the repo workspace. -
examples/basic:- Generate from the Expo blank TypeScript scaffold:
yarn create expo-app /tmp/rntl-basic-fresh --template blank-typescript --yes
- Restore the repo-specific sample app files on top of the new scaffold:
App.tsxcomponents/__tests__/theme.tsjest.config.jsjest-setup.tsbabel.config.jseslint.config.mjsREADME.md.expo-shared/assets.jsonif it existed before
- Keep the fresh Expo entrypoint (
index.ts) and updatepackage.json/app.jsonto match the repo naming and scripts.
- Generate from the Expo blank TypeScript scaffold:
-
examples/cookbook:- Generate from a router-enabled Expo scaffold:
yarn create expo-app /tmp/rntl-cookbook-fresh --example with-router --yes
- Restore the repo-specific cookbook files on top of the new scaffold:
app/- tutorial test directories such as
basics-tutorial/andbasics-tutorial-react-strict-dom/ theme.tsjest.config.jsjest-setup.tsbabel.config.js.eslintrc,.eslintignoreREADME.md- custom assets not present in the scaffold, such as
assets/gradientRNBanner.png .expo-shared/assets.jsonif it existed before
- Keep the fresh Expo Router entry setup, then reapply the cookbook-specific dependency set in
package.jsonandapp.json.
- Generate from a router-enabled Expo scaffold:
-
After regenerating either example app, validate from inside the app directory:
yarn expo install --checkyarn lintyarn typecheckyarn test --watchman=false
-
If the fresh scaffold introduces dependency-resolution churn, prefer restoring the previous
yarn.lockfirst and then runningyarn install, rather than re-resolving the whole dependency tree from scratch.
- Maintain
PR.txtat the repository root using the structure from.github/pull_request_template.md. - Keep
PR.txtaligned with the current branch diff relative toorigin/main, including tests actually run and any known validation gaps. - Do not commit
PR.txt.