Skip to content

Commit 9035fbc

Browse files
docs: restore v13 default readme (#1867)
1 parent a3c28bd commit 9035fbc

File tree

5 files changed

+177
-22
lines changed

5 files changed

+177
-22
lines changed

README-v14.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<div align="center">
2+
<a href="https://www.callstack.com/open-source?utm_campaign=generic&utm_source=github&utm_medium=referral&utm_content=react-native-testing-library" align="center">
3+
<img src="https://github.com/user-attachments/assets/4d452312-4ffd-4439-855f-a9b12ad7d6c2" alt="React Native Testing Library" />
4+
</a>
5+
<p align="center">Developer-friendly and complete React Native testing utilities that encourage good testing practices.</p>
6+
</div>
7+
8+
[![Version][version-badge]][package]
9+
[![Build Status][build-badge]][build]
10+
[![Code Coverage][coverage-badge]][coverage]
11+
[![Downloads][downloads-badge]][downloads]
12+
[![MIT License][license-badge]][license]
13+
[![Sponsored by Callstack][callstack-badge]][callstack]
14+
15+
> ⚠️ **Alpha Version:** This version is currently in alpha. APIs and behavior may change before the stable release. Please report any issues you encounter.
16+
17+
## The problem
18+
19+
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
20+
21+
## This solution
22+
23+
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
24+
25+
> The more your tests resemble the way your software is used, the more confidence they can give you.
26+
27+
This project is inspired by [React Testing Library](https://github.com/testing-library/react-testing-library). Tested to work with Jest, but it should work with other test runners as well.
28+
29+
## Installation
30+
31+
Open a Terminal in your project's folder and run:
32+
33+
```sh
34+
# Yarn install:
35+
yarn add --dev @testing-library/react-native@alpha
36+
37+
# NPM install
38+
npm install --save-dev @testing-library/react-native@alpha
39+
```
40+
41+
This library has a `peerDependencies` listing for [Test Renderer](https://github.com/mdjastrzebski/test-renderer). Make sure to install it as a dev dependency:
42+
43+
```sh
44+
# Yarn install:
45+
yarn add --dev test-renderer
46+
47+
# NPM install
48+
npm install --save-dev test-renderer
49+
```
50+
51+
### Additional Jest matchers
52+
53+
You can use the built-in Jest matchers automatically by having any import from `@testing-library/react-native` in your test.
54+
55+
## Example
56+
57+
```jsx
58+
import { render, screen, userEvent } from '@testing-library/react-native';
59+
import { QuestionsBoard } from '../QuestionsBoard';
60+
61+
// It is recommended to use userEvent with fake timers
62+
// Some events involve duration so your tests may take a long time to run.
63+
jest.useFakeTimers();
64+
65+
test('form submits two answers', async () => {
66+
const questions = ['q1', 'q2'];
67+
const onSubmit = jest.fn();
68+
69+
const user = userEvent.setup();
70+
await render(<QuestionsBoard questions={questions} onSubmit={onSubmit} />);
71+
72+
const answerInputs = screen.getAllByLabelText('answer input');
73+
74+
// simulates the user focusing on TextInput and typing text one char at a time
75+
await user.type(answerInputs[0], 'a1');
76+
await user.type(answerInputs[1], 'a2');
77+
78+
// simulates the user pressing on any pressable element
79+
await user.press(screen.getByRole('button', { name: 'Submit' }));
80+
81+
expect(onSubmit).toHaveBeenCalledWith({
82+
1: { q: 'q1', a: 'a1' },
83+
2: { q: 'q2', a: 'a2' },
84+
});
85+
});
86+
```
87+
88+
You can find the source of `QuestionsBoard` component and this example [here](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/questionsBoard.test.tsx).
89+
90+
## API / Usage
91+
92+
React Native Testing Library consists of following APIs:
93+
94+
- [`render` function](https://callstack.github.io/react-native-testing-library/docs/api/render) - render your UI components for testing purposes
95+
- [`screen` object](https://callstack.github.io/react-native-testing-library/docs/api/screen) - access rendered UI:
96+
- [Queries](https://callstack.github.io/react-native-testing-library/docs/api/queries) - find rendered components by various predicates: role, text, test ids, etc
97+
- Lifecycle methods: [`rerender`](https://callstack.github.io/react-native-testing-library/docs/api/screen#rerender), [`unmount`](https://callstack.github.io/react-native-testing-library/docs/api/screen#unmount)
98+
- Helpers: [`debug`](https://callstack.github.io/react-native-testing-library/docs/api/screen#debug), [`toJSON`](https://callstack.github.io/react-native-testing-library/docs/api/screen#tojson), [`root`](https://callstack.github.io/react-native-testing-library/docs/api/screen#root), [`container`](https://callstack.github.io/react-native-testing-library/docs/api/screen#container)
99+
- [Jest matchers](https://callstack.github.io/react-native-testing-library/docs/api/jest-matchers) - validate assumptions about your UI
100+
- [User Event](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event) - simulate common user interactions like [`press`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#press) or [`type`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#type) in a realistic way
101+
- [Fire Event](https://callstack.github.io/react-native-testing-library/docs/api/events/fire-event) - simulate any component event in a simplified way
102+
- [`renderHook` function](https://callstack.github.io/react-native-testing-library/docs/api/misc/render-hook) - render hooks for testing purposes
103+
- Miscellaneous APIs:
104+
- [Async utils](https://callstack.github.io/react-native-testing-library/docs/api/misc/async): `findBy*` queries, `waitFor`, `waitForElementToBeRemoved`
105+
- [Configuration](https://callstack.github.io/react-native-testing-library/docs/api/misc/config): `configure`, `resetToDefaults`
106+
- [Accessibility](https://callstack.github.io/react-native-testing-library/docs/api/misc/accessibility): `isHiddenFromAccessibility`
107+
- [Other](https://callstack.github.io/react-native-testing-library/docs/api/misc/other): `within`, `act`, `cleanup`
108+
109+
## Migration Guides
110+
111+
- **[Migration to 14.0](https://callstack.github.io/react-native-testing-library/docs/migration/v14)** - Drops React 18, async APIs by default
112+
- [Migration to 13.0](https://callstack.github.io/react-native-testing-library/docs/migration/v13)
113+
- [Migration to built-in Jest Matchers](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers)
114+
115+
## Troubleshooting
116+
117+
- [Troubleshooting guide](https://callstack.github.io/react-native-testing-library/docs/guides/troubleshooting)
118+
119+
## Community Resources
120+
121+
Check out our list of [Community Resources about RNTL](https://callstack.github.io/react-native-testing-library/docs/guides/community-resources).
122+
123+
## Made with ❤️ at Callstack
124+
125+
React Native Testing Library is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. [Callstack](https://callstack.com) is a group of React and React Native geeks, contact us at [hello@callstack.com](mailto:hello@callstack.com) if you need any help with these or just want to say hi!
126+
127+
Like the project? ⚛️ [Join the team](https://callstack.com/careers/?utm_campaign=Senior_RN&utm_source=github&utm_medium=readme) who does amazing stuff for clients and drives React Native Open Source! 🔥
128+
129+
---
130+
131+
Supported and used by [Rally Health](https://www.rallyhealth.com/careers).
132+
133+
<!-- badges -->
134+
135+
[version-badge]: https://img.shields.io/npm/v/@testing-library/react-native.svg?style=flat-square
136+
[package]: https://www.npmjs.com/package/@testing-library/react-native
137+
[build-badge]: https://github.com/callstack/react-native-testing-library/actions/workflows/ci.yml/badge.svg
138+
[build]: https://github.com/callstack/react-native-testing-library/actions/workflows/ci.yml
139+
[coverage-badge]: https://img.shields.io/codecov/c/github/callstack/react-native-testing-library.svg
140+
[coverage]: https://codecov.io/github/callstack/react-native-testing-library
141+
[downloads-badge]: https://img.shields.io/npm/dm/@testing-library/react-native.svg?style=flat-square
142+
[downloads]: http://www.npmtrends.com/@testing-library/react-native
143+
[license-badge]: https://img.shields.io/npm/l/@testing-library/react-native.svg
144+
[license]: https://opensource.org/licenses/MIT
145+
[callstack-badge]: https://callstack.com/images/callstack-badge.svg
146+
[callstack]: https://callstack.com/open-source/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-testing-library&utm_term=readme

README.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You want to write maintainable tests for your React Native components. As a part
1818

1919
## This solution
2020

21-
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
21+
The React Native Testing Library (RNTL) is a comprehensive solution for testing React Native components. It provides React Native runtime simulation on top of `react-test-renderer`, in a way that encourages better testing practices. Its primary guiding principle is:
2222

2323
> The more your tests resemble the way your software is used, the more confidence they can give you.
2424
@@ -36,15 +36,7 @@ yarn add --dev @testing-library/react-native
3636
npm install --save-dev @testing-library/react-native
3737
```
3838

39-
This library has a `peerDependencies` listing for [Test Renderer](https://github.com/mdjastrzebski/test-renderer). Make sure to install it as a dev dependency:
40-
41-
```sh
42-
# Yarn install:
43-
yarn add --dev test-renderer
44-
45-
# NPM install
46-
npm install --save-dev test-renderer
47-
```
39+
This library has a `peerDependencies` listing for `react-test-renderer`. Make sure that your `react-test-renderer` version matches exactly the `react` version, avoid using `^` in version number.
4840

4941
### Additional Jest matchers
5042

@@ -65,7 +57,7 @@ test('form submits two answers', async () => {
6557
const onSubmit = jest.fn();
6658

6759
const user = userEvent.setup();
68-
await render(<QuestionsBoard questions={questions} onSubmit={onSubmit} />);
60+
render(<QuestionsBoard questions={questions} onSubmit={onSubmit} />);
6961

7062
const answerInputs = screen.getAllByLabelText('answer input');
7163

@@ -93,7 +85,7 @@ React Native Testing Library consists of following APIs:
9385
- [`screen` object](https://callstack.github.io/react-native-testing-library/docs/api/screen) - access rendered UI:
9486
- [Queries](https://callstack.github.io/react-native-testing-library/docs/api/queries) - find rendered components by various predicates: role, text, test ids, etc
9587
- Lifecycle methods: [`rerender`](https://callstack.github.io/react-native-testing-library/docs/api/screen#rerender), [`unmount`](https://callstack.github.io/react-native-testing-library/docs/api/screen#unmount)
96-
- Helpers: [`debug`](https://callstack.github.io/react-native-testing-library/docs/api/screen#debug), [`toJSON`](https://callstack.github.io/react-native-testing-library/docs/api/screen#tojson), [`root`](https://callstack.github.io/react-native-testing-library/docs/api/screen#root), [`container`](https://callstack.github.io/react-native-testing-library/docs/api/screen#container)
88+
- Helpers: [`debug`](https://callstack.github.io/react-native-testing-library/docs/api/screen#debug), [`toJSON`](https://callstack.github.io/react-native-testing-library/docs/api/screen#tojson), [`root`](https://callstack.github.io/react-native-testing-library/docs/api/screen#root)
9789
- [Jest matchers](https://callstack.github.io/react-native-testing-library/docs/api/jest-matchers) - validate assumptions about your UI
9890
- [User Event](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event) - simulate common user interactions like [`press`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#press) or [`type`](https://callstack.github.io/react-native-testing-library/docs/api/events/user-event#type) in a realistic way
9991
- [Fire Event](https://callstack.github.io/react-native-testing-library/docs/api/events/fire-event) - simulate any component event in a simplified way
@@ -106,7 +98,6 @@ React Native Testing Library consists of following APIs:
10698

10799
## Migration Guides
108100

109-
- **[Migration to 14.0](https://callstack.github.io/react-native-testing-library/docs/migration/v14)** - Drops React 18, async APIs by default
110101
- [Migration to 13.0](https://callstack.github.io/react-native-testing-library/docs/migration/v13)
111102
- [Migration to built-in Jest Matchers](https://callstack.github.io/react-native-testing-library/docs/migration/jest-matchers)
112103

website/docs/14.x/docs/migration/v14.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { PackageManagerTabs } from 'rspress/theme';
22

33
# Migration to 14.x
44

5+
:::warning Alpha Version
6+
7+
This version is currently in alpha. APIs and behavior may change before the stable release. Please report any issues you encounter.
8+
9+
:::
10+
511
This guide describes the migration to React Native Testing Library version 14 from version 13.x.
612

713
## Overview
@@ -90,10 +96,10 @@ Remove React Test Renderer and its type definitions from your dev dependencies,
9096

9197
<PackageManagerTabs
9298
command={{
93-
npm: 'npm uninstall react-test-renderer @types/react-test-renderer\nnpm install -D test-renderer@^0.14.0',
94-
yarn: 'yarn remove react-test-renderer @types/react-test-renderer\nyarn add -D test-renderer@^0.14.0',
95-
pnpm: 'pnpm remove react-test-renderer @types/react-test-renderer\npnpm add -D test-renderer@^0.14.0',
96-
bun: 'bun remove react-test-renderer @types/react-test-renderer\nbun add -D test-renderer@^0.14.0',
99+
npm: 'npm uninstall react-test-renderer @types/react-test-renderer\nnpm install -D test-renderer',
100+
yarn: 'yarn remove react-test-renderer @types/react-test-renderer\nyarn add -D test-renderer',
101+
pnpm: 'pnpm remove react-test-renderer @types/react-test-renderer\npnpm add -D test-renderer',
102+
bun: 'bun remove react-test-renderer @types/react-test-renderer\nbun add -D test-renderer',
97103
}}
98104
/>
99105

@@ -427,7 +433,7 @@ Updates your `package.json`:
427433

428434
- Removes React Test Renderer (`react-test-renderer` and `@types/react-test-renderer`)
429435
- Adds Test Renderer (`test-renderer`)
430-
- Updates `@testing-library/react-native` to `^14.0.0`
436+
- Updates `@testing-library/react-native` to alpha version
431437

432438
<PackageManagerTabs
433439
command={{

website/docs/14.x/docs/start/intro.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Introduction
22

3+
:::warning Alpha Version
4+
5+
This version is currently in alpha. APIs and behavior may change before the stable release. Please report any issues you encounter.
6+
7+
:::
8+
39
## The problem
410

511
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and focus on making your tests give you the confidence they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.

website/docs/14.x/docs/start/quick-start.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ import { PackageManagerTabs } from 'rspress/theme';
22

33
# Quick Start
44

5+
:::warning Alpha Version
6+
7+
This version is currently in alpha. APIs and behavior may change before the stable release. Please report any issues you encounter.
8+
9+
:::
10+
511
## Installation
612

713
Open a Terminal in your project's folder and run:
814

915
<PackageManagerTabs
1016
command={{
11-
npm: 'npm install -D @testing-library/react-native',
12-
yarn: 'yarn add -D @testing-library/react-native',
13-
pnpm: 'pnpm add -D @testing-library/react-native',
14-
bun: 'bun add -D @testing-library/react-native',
17+
npm: 'npm install -D @testing-library/react-native@alpha',
18+
yarn: 'yarn add -D @testing-library/react-native@alpha',
19+
pnpm: 'pnpm add -D @testing-library/react-native@alpha',
20+
bun: 'bun add -D @testing-library/react-native@alpha',
1521
}}
1622
/>
1723

0 commit comments

Comments
 (0)