To test a React error boundary, render a child that throws during rendering and assert that the boundary’s fallback is visible. Test error reporting separately: pass the boundary a spy or reporting adapter and verify it receives the error and component context. A visible fallback proves the user-facing behavior; it does not prove an error was reported.
How do I test an error boundary’s fallback?
Use a deterministic component that throws while React renders it, place it below the same boundary your application uses, and assert the fallback through an accessible role or text. Testing Library’s FAQ recommends checking the fallback after a child throws; if the boundary does not catch the error, the render call throws instead.
function BrokenChild() {
throw new Error('render failed');
}
render(
<ErrorBoundary fallback={<p role="alert">We hit a problem</p>}>
<BrokenChild />
</ErrorBoundary>,
);
expect(screen.getByRole('alert')).toHaveTextContent('We hit a problem');
This example assumes an ErrorBoundary component that accepts a fallback prop; use your application’s actual boundary API. Prefer an assertion on what a user can see over checking private state or implementation details.
How do I test error reporting separately?
A fallback and a report are two separate outcomes. React documents getDerivedStateFromError as the mechanism for updating state so a boundary can render fallback UI, and componentDidCatch(error, info) as a place to log the error. The React Component reference describes info.componentStack as component ancestry and context useful for diagnostics.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Inject a spy, mock, or test reporting adapter into the boundary, trigger the same rendering failure, then assert that the reporter received the expected error and useful component information. Keep that assertion distinct from the fallback assertion: a test can pass for one behavior while the other is broken.
Do not rely solely on window.onerror or another global handler to prove reporting works. React documents that errors caught by componentDidCatch behave differently by mode: development errors bubble to window, while in production caught errors do not bubble to ancestor handlers. Explicitly verify the reporting path your application depends on.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
What errors do boundaries catch—and what do they miss?
A boundary handles errors thrown while rendering descendants in the part of the tree it wraps. It does not catch every JavaScript error. React’s documentation identifies these important exclusions:
- Errors from event handlers. Test the handler’s own catch, reporting, or application behavior.
- Errors during server rendering.
- Errors thrown by the boundary itself; test those at a higher boundary or layer.
- Most asynchronous callbacks, including callbacks such as
setTimeoutandrequestAnimationFrame. Trigger and test the callback’s own error-handling path.
React documents an exception for errors thrown inside the function returned by useTransition’s startTransition. Do not generalize that exception to arbitrary asynchronous work.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsRank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
How do React 18 and React 19 affect boundary tests?
Framework diagnostics can add console output when React encounters a render error. Testing Library’s FAQ documents extended console.error output in React 18 and extended console.warn output in React 19. Such output is not, by itself, evidence that the fallback assertion failed.
| Version or option | Documented behavior | Testing implication |
|---|---|---|
| React 18 | Testing Library documents extended console.error output for boundary errors. |
Do not mistake framework diagnostics for a failed assertion. The render option onCaughtError is unsupported in React 18. |
| React 19 | Testing Library documents extended console.warn output and supports the render option onCaughtError. |
Use onCaughtError when intentionally observing caught errors or suppressing the extra warning as documented. |
The current React Testing Library API also documents onRecoverableError for errors React automatically recovers from. That callback is different from onCaughtError, which concerns an error caught by a boundary. Assert the callback relevant to the behavior under test; neither callback replaces checking the user-visible fallback.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Testing Library’s API marks legacyRoot as an option for React 18 and earlier. Check the API supported by the React and Testing Library versions in your project rather than copying render options from an example targeting another major version. If you suppress console output, keep the spy narrow and restore it after each test so unrelated warnings remain visible.
Should reporting live in the boundary or at the React root?
These are different integration layers, not universal substitutes. A boundary-level componentDidCatch(error, info) is a natural place to report failures caught by that boundary. React 19 root callbacks let an integration observe caught, uncaught, and recoverable errors at the root, using separate callbacks for those paths.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Sentry’s June 17, 2024 React 19 support release note describes connecting Sentry.reactErrorHandler to root onUncaughtError, onCaughtError, and onRecoverableError hooks, and says component stacks are attached to new errors. This is a dated vendor release note, not a guarantee about every current SDK version; confirm the behavior against the installed SDK and its current documentation before relying on it.
Whichever integration you use, test its contract directly. For a boundary reporter, assert the arguments passed by componentDidCatch; for a root integration, exercise the relevant root error path and assert the corresponding callback and payload. A caught production error may not reach a global handler, so an explicit reporting assertion matters.
Where should boundaries sit in a component or route tree?
Place a boundary around a meaningful area that can show a useful fallback, rather than wrapping every individual component. React gives a conversation list or a message as reasonable scopes and notes that a single avatar is generally too fine-grained. Test the boundary at the same scope users will experience: make a descendant in that area fail and verify that area’s fallback.
React currently documents error boundaries as class components; there is no direct function-component implementation. You can reuse a class boundary or use a library such as react-error-boundary rather than writing one from scratch.
Free tools Windows power users keep installed
One-click scans. No signup required.
For React Router, route error boundaries are a separate layer: the nearest route boundary handles a route loader, action, or component error, and a root boundary provides minimum coverage. The React Router error-boundary guide distinguishes this routing behavior from ordinary form validation and dedicated error reporting. Test a route failure against the closest route fallback and its route-specific state; do not treat that as a replacement for testing your reporting integration.
Quick Recap
What should a focused test suite cover?
| Scenario | Trigger | Assert |
|---|---|---|
| Boundary fallback | A descendant throws during rendering. | The expected fallback content or accessible alert is visible. |
| Reporting side effect | The same deterministic rendering failure. | The reporter receives the error and useful component context. |
| Missing or ineffective boundary | Render the throwing child without an effective boundary. | The render failure is surfaced; do not expect fallback UI. |
| Event-handler failure | Invoke the handler that throws. | The handler’s own error handling, reporting, or resulting behavior. |
| Async callback failure | Trigger the timer, callback, or async workflow. | That workflow’s own error-handling or reporting path. |
| Boundary’s own failure | Make the boundary’s render or reporting path fail. | Handling at a higher layer, since the same boundary cannot catch its own error. |
| React 19 root callback | Exercise the applicable caught, uncaught, or recoverable path. | The relevant callback and payload, separately from fallback UI. |
| Route failure | Trigger a route loader, action, or component error. | The nearest route boundary and route-specific state. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

