Skip to content

Commit a47fd8f

Browse files
committed
migration guide
1 parent dc6c062 commit a47fd8f

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ This guide describes the migration to React Native Testing Library version 14 fr
1212

1313
## Overview
1414

15-
RNTL v14 is a major release that **drops support for React 18** and fully embraces React 19's async-first paradigm. Key changes include:
15+
RNTL v14 drops support for React 18 and adopts React 19's async rendering model. Here's what changed:
1616

17-
- **React 19+ required**: Minimum supported versions are React 19.0.0 and React Native 0.78+
18-
- **Async APIs by default**: `render`, `renderHook`, `fireEvent`, and `act` are now async
19-
- **New renderer**: Switched from deprecated [React Test Renderer](https://reactjs.org/docs/test-renderer.html) to [Test Renderer](https://github.com/mdjastrzebski/test-renderer)
20-
- **API cleanup**: Removed deprecated APIs (`update`, `getQueriesForElement`, `UNSAFE_root`, `concurrentRoot` option)
21-
- **Safe `container` API**: Reintroduced `container` which is now safe to use
17+
- React 19.0.0+ and React Native 0.78+ are now required
18+
- `render`, `renderHook`, `fireEvent`, and `act` are now async
19+
- Switched from deprecated [React Test Renderer](https://reactjs.org/docs/test-renderer.html) to [Test Renderer](https://github.com/mdjastrzebski/test-renderer)
20+
- Removed deprecated APIs: `update`, `getQueriesForElement`, `UNSAFE_root`, `concurrentRoot` option
21+
- Reintroduced `container` API, which is now safe to use
2222

2323
:::info React 18 Users
2424

@@ -67,13 +67,13 @@ After running the codemods, review the changes and run your tests.
6767

6868
### Test Renderer replaces React Test Renderer
6969

70-
In v14, React Native Testing Library now uses [Test Renderer](https://github.com/mdjastrzebski/test-renderer) instead of the deprecated [React Test Renderer](https://reactjs.org/docs/test-renderer.html). Test Renderer is a modern, actively maintained alternative that provides better compatibility with React 19 and improved type safety.
70+
In v14, React Native Testing Library uses [Test Renderer](https://github.com/mdjastrzebski/test-renderer) instead of the deprecated [React Test Renderer](https://reactjs.org/docs/test-renderer.html). Test Renderer works with React 19 and has better TypeScript support.
7171

7272
**What changed:**
7373

74-
- The underlying renderer has been switched from React Test Renderer to Test Renderer
75-
- This change is mostly internal and should not require code changes in most cases
76-
- Type definitions have been updated to use [`HostElement`](https://github.com/mdjastrzebski/test-renderer#hostelement) from Test Renderer instead of `ReactTestInstance`
74+
- The underlying renderer is now Test Renderer instead of React Test Renderer
75+
- This is mostly an internal change; your tests should work without modifications in most cases
76+
- Type definitions now use [`HostElement`](https://github.com/mdjastrzebski/test-renderer#hostelement) from Test Renderer instead of `ReactTestInstance`
7777

7878
**Migration:**
7979

@@ -117,11 +117,11 @@ import type { HostElement } from 'test-renderer';
117117

118118
**Note:** Most users won't need to update type imports, as React Native Testing Library now exports the necessary types directly.
119119

120-
For more details, see the [Test Renderer documentation](https://github.com/mdjastrzebski/test-renderer).
120+
See the [Test Renderer documentation](https://github.com/mdjastrzebski/test-renderer) for more.
121121

122122
### Async APIs by Default
123123

124-
With React 18 support dropped, RNTL v14 fully embraces React 19's async rendering model. The following functions are now async by default:
124+
With React 18 support dropped, RNTL v14 uses React 19's async rendering model. The following functions are now async by default:
125125

126126
- `render()` → returns `Promise<RenderResult>`
127127
- `rerender()` and `unmount()` → return `Promise<void>`
@@ -131,13 +131,13 @@ With React 18 support dropped, RNTL v14 fully embraces React 19's async renderin
131131

132132
:::tip Already using async APIs?
133133

134-
If you adopted the async APIs introduced in RNTL v13.3 (`renderAsync`, `fireEventAsync`, `renderHookAsync`), simply rename them to their non-async counterparts (`render`, `fireEvent`, `renderHook`). The async versions have been removed as the standard APIs are now async by default.
134+
If you adopted the async APIs introduced in RNTL v13.3 (`renderAsync`, `fireEventAsync`, `renderHookAsync`), rename them to their non-async counterparts (`render`, `fireEvent`, `renderHook`). The async versions have been removed since the standard APIs are now async by default.
135135

136136
:::
137137

138138
#### `render` is now async {#render-async-default}
139139

140-
In v14, `render` is now async by default and returns a Promise. This change enables proper support for async React features like `Suspense` boundary or `use()` hook.
140+
In v14, `render` is async by default and returns a Promise. This allows proper support for `Suspense` boundaries and the `use()` hook.
141141

142142
**Before (v13):**
143143

@@ -161,11 +161,11 @@ it('should render component', async () => {
161161
});
162162
```
163163

164-
For more details, see the [`render` API documentation](/docs/api/render).
164+
See the [`render` API documentation](/docs/api/render).
165165

166166
#### `renderHook` is now async
167167

168-
In v14, `renderHook` is now async by default and returns a Promise.
168+
In v14, `renderHook` is async by default and returns a Promise.
169169

170170
**Before (v13):**
171171

@@ -193,11 +193,11 @@ it('should test hook', async () => {
193193
});
194194
```
195195

196-
For more details, see the [`renderHook` API documentation](/docs/api/misc/render-hook).
196+
See the [`renderHook` API documentation](/docs/api/misc/render-hook).
197197

198198
#### `fireEvent` is now async
199199

200-
In v14, `fireEvent` and its helpers (`press`, `changeText`, `scroll`) are now async by default and return a Promise.
200+
In v14, `fireEvent` and its helpers (`press`, `changeText`, `scroll`) are async by default and return a Promise.
201201

202202
**Before (v13):**
203203

@@ -225,13 +225,12 @@ it('should press button', async () => {
225225

226226
#### `act` is now async
227227

228-
In v14, `act` is now async by default and always returns a Promise. You should always `await` the result of `act()`.
228+
In v14, `act` is async by default and always returns a Promise. You should always `await` the result of `act()`.
229229

230230
**What changed:**
231231

232-
- `act` now always returns a `Promise<T>` instead of `T | Thenable<T>`
232+
- `act` now always returns `Promise<T>` instead of `T | Thenable<T>`
233233
- `act` should always be awaited
234-
- The API is more consistent and predictable
235234

236235
:::note
237236

@@ -267,14 +266,11 @@ it('should update state', async () => {
267266

268267
**Note**: Even if your callback is synchronous, you should still use `await act(...)` as `act` now always returns a Promise.
269268

270-
For more details, see the [`act` API documentation](/docs/api/misc/other#act).
269+
See the [`act` API documentation](/docs/api/misc/other#act).
271270

272-
#### Benefits of Async APIs
271+
#### Why async APIs?
273272

274-
- **Suspense support**: Properly handles `Suspense` boundaries and `use()` hook
275-
- **Better timing**: Ensures all pending React updates are executed before assertions
276-
- **Simpler mental model**: All rendering operations are consistently async
277-
- **Future-proof**: Aligns with React's direction toward async rendering
273+
The async APIs properly handle `Suspense` boundaries and the `use()` hook, and ensure all pending React updates complete before assertions run. This matches React 19's async rendering model.
278274

279275
### Removed APIs
280276

@@ -343,7 +339,7 @@ const input = screen.getByPlaceholderText('Enter text');
343339

344340
#### `concurrentRoot` option removed
345341

346-
The `concurrentRoot` option has been removed from both `render` options and `configure` function. In v14, concurrent rendering is always enabled by default, as it is the standard rendering mode for React 19 and React Native's New Architecture.
342+
The `concurrentRoot` option has been removed from both `render` options and `configure` function. In v14, concurrent rendering is always enabled, since it's the standard rendering mode for React 19 and React Native's New Architecture.
347343

348344
```ts
349345
// Before (v13)
@@ -355,11 +351,11 @@ configure({ concurrentRoot: false }); // Disable globally
355351
await render(<MyComponent />); // Always uses concurrent rendering
356352
```
357353

358-
**Migration:** Simply remove any `concurrentRoot` options from your `render` calls and `configure` function. If you were explicitly setting `concurrentRoot: true`, no changes are needed beyond removing the option. If you were setting `concurrentRoot: false` to disable concurrent rendering, this is no longer supported in v14.
354+
**Migration:** Remove any `concurrentRoot` options from your `render` calls and `configure` function. If you were setting `concurrentRoot: true`, just remove the option. If you were setting `concurrentRoot: false` to disable concurrent rendering, this is no longer supported in v14.
359355

360356
### `container` API reintroduced
361357

362-
In v14, the `container` API has been reintroduced and is now safe to use. Previously, `container` was renamed to `UNSAFE_root` in v12 due to behavioral differences from React Testing Library's `container`. In v14, `container` now returns a pseudo-element container whose children are the elements you asked to render, making it safe and consistent with React Testing Library's behavior.
358+
In v14, the `container` API has been reintroduced and is now safe to use. Previously, `container` was renamed to `UNSAFE_root` in v12 due to behavioral differences from React Testing Library's `container`. Now `container` returns a pseudo-element container whose children are the elements you rendered, consistent with React Testing Library's behavior.
363359

364360
**What changed:**
365361

@@ -394,11 +390,11 @@ it('should access container', async () => {
394390
});
395391
```
396392

397-
For more details, see the [`screen` API documentation](/docs/api/screen#container).
393+
See the [`screen` API documentation](/docs/api/screen#container).
398394

399395
### Text string validation enforced by default
400396

401-
In v14, Test Renderer automatically enforces React Native's requirement that text strings must be rendered within a `<Text>` component. This means the `unstable_validateStringsRenderedWithinText` option has been removed from `RenderOptions`, as this validation is now always enabled.
397+
In v14, Test Renderer enforces React Native's requirement that text strings must be rendered within a `<Text>` component. The `unstable_validateStringsRenderedWithinText` option has been removed from `RenderOptions` since this validation is now always on.
402398

403399
**What changed:**
404400

@@ -425,7 +421,7 @@ If you were relying on the previous behavior where strings could be rendered out
425421

426422
## Codemods
427423

428-
We provide two codemods to automate the migration. Both codemods are **safe to run multiple times** - they will only transform code that hasn't been migrated yet.
424+
Two codemods are available to automate the migration. Both are safe to run multiple times - they only transform code that hasn't been migrated yet.
429425

430426
### `rntl-v14-update-deps`
431427

0 commit comments

Comments
 (0)