test-renderer is a modern, lightweight testing utility for React, serving as a replacement for the deprecated `react-test-renderer` package. Currently stable at version 1.2.0, this library adheres to a rapid release cadence, with minor versions specifically tracking compatibility lines for new React minor releases (e.g., 1.2.x for React 19.2). It leverages React Reconciler to construct an in-memory "Test Output Tree" and a serializable "JSON Output Tree," making it ideal for snapshot testing and detailed component inspection. It is a core dependency for libraries like React Native Testing Library and provides direct access to React Reconciler options for advanced use cases, while fully supporting modern React 19 features such as Actions, useActionState, and useEffectEvent.
npm install test-rendererVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates rendering, updating, and snapshot testing a React component using `test-renderer` and `act`.
Update your `package.json` dependency to `test-renderer` and change all `import` statements from `universal-test-renderer` to `test-renderer`.
Review the `docs/versioning.md` and compatibility table in the README to ensure your `test-renderer` version aligns with your installed `react` version for optimal support of new React features.
Wrap your `renderer.render()` calls and any state-modifying interactions within `await act(async () => { /* ... */ });`.Always pass a valid React element, such as `<MyComponent />` or `<div>Hello</div>`, to `renderer.render()`.
Ensure your project and testing setup are configured for ES Modules (e.g., `"type": "module"` in `package.json`, proper bundler/transpiler configuration for Jest/Vitest) and use `import` statements.
Wrap the code that causes the update (e.g., `renderer.render()`, event dispatches) with `await act(async () => { /* ... */ });`.Modify your `renderer.render()` call to always pass a valid React element, for example: `renderer.render(<div>Content</div>)` or `renderer.render(<MyComponent />)`.
Configure your `package.json` with `"type": "module"`, or ensure your test runner (e.g., Jest) is set up to transpile ES Modules, or use an ES Module loader.