You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/14.x/docs/start/migration-v14.mdx
+29-33Lines changed: 29 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,13 @@ This guide describes the migration to React Native Testing Library version 14 fr
12
12
13
13
## Overview
14
14
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:
16
16
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)
-**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)
-Reintroduced`container` API, which is now safe to use
22
22
23
23
:::info React 18 Users
24
24
@@ -67,13 +67,13 @@ After running the codemods, review the changes and run your tests.
67
67
68
68
### Test Renderer replaces React Test Renderer
69
69
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.
71
71
72
72
**What changed:**
73
73
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`
77
77
78
78
**Migration:**
79
79
@@ -117,11 +117,11 @@ import type { HostElement } from 'test-renderer';
117
117
118
118
**Note:** Most users won't need to update type imports, as React Native Testing Library now exports the necessary types directly.
119
119
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.
121
121
122
122
### Async APIs by Default
123
123
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:
125
125
126
126
-`render()` → returns `Promise<RenderResult>`
127
127
-`rerender()` and `unmount()` → return `Promise<void>`
@@ -131,13 +131,13 @@ With React 18 support dropped, RNTL v14 fully embraces React 19's async renderin
131
131
132
132
:::tip Already using async APIs?
133
133
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.
135
135
136
136
:::
137
137
138
138
#### `render` is now async {#render-async-default}
139
139
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.
**Note**: Even if your callback is synchronous, you should still use `await act(...)` as `act` now always returns a Promise.
269
268
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).
271
270
272
-
#### Benefits of Async APIs
271
+
#### Why async APIs?
273
272
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.
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.
**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.
359
355
360
356
### `container` API reintroduced
361
357
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.
For more details, see the [`screen` API documentation](/docs/api/screen#container).
393
+
See the [`screen` API documentation](/docs/api/screen#container).
398
394
399
395
### Text string validation enforced by default
400
396
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.
402
398
403
399
**What changed:**
404
400
@@ -425,7 +421,7 @@ If you were relying on the previous behavior where strings could be rendered out
425
421
426
422
## Codemods
427
423
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.
0 commit comments