Migration to 14.x
This version is currently in alpha. APIs and behavior may change before the stable release. Please report any issues you encounter.
This guide describes the migration to React Native Testing Library version 14 from version 13.x.
Overview
RNTL v14 drops support for React 18 and adopts React 19's async rendering model. Here's what changed:
- React 19.0.0+ and React Native 0.78+ are now required
render,renderHook,fireEvent, andactare now async- Switched from deprecated React Test Renderer to Test Renderer
- Removed deprecated APIs:
update,getQueriesForElement,UNSAFE_root,concurrentRootoption - Reintroduced
containerAPI, which is now safe to use
If you need to support React 18, please continue using RNTL v13.x.
Quick Migration
We provide codemods to automate most of the migration:
Step 1: Update dependencies
Step 2: Update test code to async
After running the codemods, review the changes and run your tests.
Breaking Changes
Supported React and React Native versions
This version requires React 19+ and React Native 0.78+. If you need to support React 18, please use the latest v13.x version.
Test Renderer replaces React Test Renderer
In v14, React Native Testing Library uses Test Renderer instead of the deprecated React Test Renderer. Test Renderer works with React 19 and has better TypeScript support.
What changed:
- The underlying renderer is now Test Renderer instead of React Test Renderer
- This is mostly an internal change; your tests should work without modifications in most cases
- Type definitions now use
HostElementfrom Test Renderer instead ofReactTestInstance
Migration:
1. Update dependencies
Run codemod for updating dependencies:
Manual changes
Remove React Test Renderer and its type definitions from your dev dependencies, and add Test Renderer:
2. Update type imports (if needed)
If you were directly importing types from React Test Renderer, you may need to update your imports:
Note: Most users won't need to update type imports, as React Native Testing Library now exports the necessary types directly.
See the Test Renderer documentation for more.
Async APIs by Default
With React 18 support dropped, RNTL v14 uses React 19's async rendering model. The following functions are now async by default:
render()→ returnsPromise<RenderResult>rerender()andunmount()→ returnPromise<void>renderHook()→ returnsPromise<RenderHookResult>fireEvent()and helpers (press,changeText,scroll) → returnPromise<void>act()→ always returnsPromise<T>
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.
render is now async
In v14, render is async by default and returns a Promise. This allows proper support for Suspense boundaries and the use() hook.
Before (v13):
After (v14):
See the render API documentation.
renderHook is now async
In v14, renderHook is async by default and returns a Promise.
Before (v13):
After (v14):
See the renderHook API documentation.
fireEvent is now async
In v14, fireEvent and its helpers (press, changeText, scroll) are async by default and return a Promise.
Before (v13):
After (v14):
act is now async
In v14, act is async by default and always returns a Promise. You should always await the result of act().
What changed:
actnow always returnsPromise<T>instead ofT | Thenable<T>actshould always be awaited
The transition to async act may prevent testing very short transient states, as awaiting act will flush all pending updates before returning.
Before (v13):
After (v14):
Note: Even if your callback is synchronous, you should still use await act(...) as act now always returns a Promise.
See the act API documentation.
Why async APIs?
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.
Removed APIs
update alias removed
The update alias for rerender has been removed. Use rerender instead:
getQueriesForElement export removed
The getQueriesForElement export alias for within has been removed. Use within instead:
Note: getQueriesForElement was just an alias for within, so the functionality is identical - only the import needs to change.
UNSAFE_root removed
UNSAFE_root has been removed. Use container to access the pseudo-element container, or root to access the first rendered host element:
Legacy UNSAFE_* queries removed
The legacy UNSAFE_getAllByType, UNSAFE_getByType, UNSAFE_getAllByProps, and UNSAFE_getByProps queries have been removed. These queries could return composite (user-defined) components, which is no longer supported with Test Renderer as it only renders host elements.
If you were using these legacy queries, you should refactor your tests to use the standard queries (getByRole, getByText, getByTestId, etc.) which target host elements.
concurrentRoot option removed
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: 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.
container API reintroduced
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.
What changed:
screen.containeris now available and safe to usecontainerreturns a pseudo-element container from Test Renderer- The container's children are the elements you rendered
UNSAFE_roothas been removed
Before (v13):
After (v14):
See the screen API documentation.
Text string validation enforced by default
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.
What changed:
- Text string validation is now always enabled and cannot be disabled
- The
unstable_validateStringsRenderedWithinTextoption has been removed - Tests will now throw
Invariant Violation: Text strings must be rendered within a <Text> componenterrors when attempting to render strings outside of<Text>components, matching React Native's runtime behavior
Migration:
If you were using unstable_validateStringsRenderedWithinText: true in your render options, you can simply remove this option as the validation is now always enabled:
If you were relying on the previous behavior where strings could be rendered outside of <Text> components, you'll need to fix your components to wrap strings in <Text> components, as this matches React Native's actual runtime behavior.
Codemods
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.
rntl-v14-update-deps
Updates your package.json:
- Removes React Test Renderer (
react-test-rendererand@types/react-test-renderer) - Adds Test Renderer (
test-renderer) - Updates
@testing-library/react-nativeto alpha version
rntl-v14-async-functions
Transforms test files:
- Adds
awaittorender(),act(),renderHook(),fireEvent()calls - Makes test functions async when needed
- Handles
screen.rerender(),screen.unmount(), and renderer methods
Custom render functions
If you have custom render helpers (like renderWithProviders), you can specify them using the customRenderFunctions parameter. The codemod will then also transform calls to these functions:
This will add await to your custom render calls and make the containing test functions async, just like it does for the standard render function.
Limitations
- Helper functions defined in test files are not transformed by default
- Namespace imports (
import * as RNTL) are not handled
Full Changelog
https://github.com/callstack/react-native-testing-library/compare/v13.3.3...v14.0.0
