test-renderer 0.15.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Test Renderer for React
2
2
 
3
- A lightweight, JS-only building block for creating Testing Library-style libraries.
3
+ A lightweight test renderer for React and a modern replacement for the deprecated React Test Renderer.
4
4
 
5
5
  This library is used by [React Native Testing Library](https://github.com/callstack/react-native-testing-library) but should work with any React variant.
6
6
 
7
- This library replaces the deprecated React Test Renderer. It uses [React Reconciler](https://github.com/facebook/react/tree/main/packages/react-reconciler) to build a custom renderer that operates on host elements by default, and provides escape hatches for complex use-cases. Most React Reconciler options are exposed through `RootOptions`.
7
+ It uses [React Reconciler](https://github.com/facebook/react/tree/main/packages/react-reconciler) to build a custom renderer that operates on host elements by default, and provides escape hatches for complex use-cases. Most React Reconciler options are exposed through `RootOptions`.
8
+
9
+ For release and compatibility policy, see [docs/versioning.md](./docs/versioning.md).
8
10
 
9
11
  ## Installation
10
12
 
@@ -36,13 +38,17 @@ test("renders a component", async () => {
36
38
  });
37
39
  ```
38
40
 
39
- ## Supported React Features
41
+ ## React 19 Compatibility Lines
42
+
43
+ Starting with `1.x`, `test-renderer` tracks preferred React 19 compatibility lines while keeping a broad React 19 peer range so installs do not get blocked between React minor releases.
40
44
 
41
- This library supports all modern React features including:
45
+ | `test-renderer` version | `react` version | `react-reconciler` version | Notable React features |
46
+ | ----------------------- | --------------- | -------------------------- | ------------------------------------------------------- |
47
+ | `1.0.x` | `19.0` | `~0.31.0` | Actions, `useActionState`, `useOptimistic`, `use` |
48
+ | `1.1.x` | `19.1` | `~0.32.0` | Owner Stack support, CSS-selector-safe `useId()` format |
49
+ | `1.2.x` | `19.2` | `~0.33.0` | `<Activity />`, `useEffectEvent` |
42
50
 
43
- - Concurrent rendering
44
- - Error boundaries
45
- - Suspense boundaries
51
+ These examples are illustrative, not exhaustive. New React-minor-specific support lands on the matching preferred React / `react-reconciler` line for each `1.x` release, even though the package publishes a broad React 19 peer range.
46
52
 
47
53
  ## Test Output Tree
48
54
 
@@ -76,7 +82,7 @@ Creates a new test renderer root instance.
76
82
 
77
83
  **Returns:** A `Root` object with the following properties:
78
84
 
79
- - `render(element: ReactElement)`: Renders a React element into the root. Must be called within `act()`.
85
+ - `render(element: ReactElement)`: Renders a React element into the root. Fragments are supported. Non-element root values such as strings or `null` are not supported. Must be called within `act()`.
80
86
  - `unmount()`: Unmounts the root and cleans up. Must be called within `act()`.
81
87
  - `container`: A `TestInstance` wrapper that contains the rendered element(s). Use this to query and inspect the rendered tree.
82
88
 
@@ -100,9 +106,9 @@ Configuration options for the test renderer. Many of these options correspond to
100
106
  | `transformHiddenInstanceProps` | `({ props, type }: { props: Record<string, unknown>; type: string }) => Record<string, unknown>` | Transforms host instance props when React marks an instance as hidden (for example, while Suspense fallback is shown). Return a new props object instead of mutating the provided one. When provided, hidden instances stay visible in `children` and `toJSON()` output using transformed props. |
101
107
  | `identifierPrefix` | `string` | A string prefix React uses for IDs generated by `useId()`. Useful to avoid conflicts when using multiple roots. |
102
108
  | `isStrictMode` | `boolean` | Enable React Strict Mode. When enabled, components render twice and effects run twice in development. |
103
- | `onCaughtError` | `(error: unknown, errorInfo: { componentStack?: string }) => void` | Callback called when React catches an error in an Error Boundary. Called with the error caught by the Error Boundary and an errorInfo object containing the component stack. |
104
- | `onUncaughtError` | `(error: unknown, errorInfo: { componentStack?: string }) => void` | Callback called when an error is thrown and not caught by an Error Boundary. Called with the error that was thrown and an errorInfo object containing the component stack. |
105
- | `onRecoverableError` | `(error: unknown, errorInfo: { componentStack?: string }) => void` | Callback called when React automatically recovers from errors. Called with an error React throws and an errorInfo object containing the component stack. Some recoverable errors may include the original error cause as `error.cause`. |
109
+ | `onCaughtError` | `(error: unknown, errorInfo: { componentStack: string }) => void` | Callback called when React catches an error in an Error Boundary. Called with the error caught by the Error Boundary and an errorInfo object containing the component stack. |
110
+ | `onUncaughtError` | `(error: unknown, errorInfo: { componentStack: string }) => void` | Callback called when an error is thrown and not caught by an Error Boundary. Called with the error that was thrown and an errorInfo object containing the component stack. |
111
+ | `onRecoverableError` | `(error: unknown, errorInfo: { componentStack: string }) => void` | Callback called when React automatically recovers from errors. Called with an error React throws and an errorInfo object containing the component stack. Some recoverable errors may include the original error cause as `error.cause`. |
106
112
 
107
113
  ### `TestInstance` {#test-instance}
108
114
 
@@ -111,8 +117,8 @@ A wrapper around rendered host elements with a DOM-like API for querying and ins
111
117
  **Properties:**
112
118
 
113
119
  - `type: string`: The element type (e.g., `"View"`, `"div"`). Returns an empty string for the container element.
114
- - `props: Record<string, all>`: The element's props object.
115
- - `children: HostNode[]`: Array of child nodes (elements and text strings). Hidden children are excluded by default, but are included when `transformHiddenInstanceProps` is configured.
120
+ - `props: Record<string, any>`: The element's props object.
121
+ - `children: TestNode[]`: Array of child nodes (elements and text strings). Hidden children are excluded by default, but are included when `transformHiddenInstanceProps` is configured.
116
122
  - `parent: TestInstance | null`: The parent element, or `null` if this is the root container.
117
123
  - `unstable_fiber: Fiber | null`: Access to the underlying React Fiber node. **Warning:** This is an unstable API that exposes internal React Reconciler structures which may change without warning in future React versions. Use with caution and only when absolutely necessary.
118
124