To test an error boundary, make a descendant throw during rendering and assert that the fallback users can see appears. Test error reporting separately by checking that your reporter receives the error and useful component context. A fallback proves recovery UI works; it does not prove that the failure was logged.
How do I test an error boundary?
Use a deterministic component that throws while rendering, place it beneath the boundary used by your application, and assert on the fallback’s accessible content rather than the boundary’s internal state. This is the core pattern in the React Testing Library FAQ: if no effective boundary catches the child error, the render call throws instead of producing the expected fallback.
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');
Adapt the boundary props and test setup to your implementation. The important assertion is that a user-facing fallback is present after a descendant’s render fails. If your boundary is intended to preserve unaffected parts of the page, you can also assert that their visible content remains; keep such assertions tied to behavior the interface promises.
Test the missing-boundary case differently
If you deliberately render the throwing child without an effective boundary, assert that the render fails or is reported by your test setup. Do not expect fallback UI from a boundary that is absent or does not enclose the child.
#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.
How to test error reporting separately
Fallback rendering and reporting are distinct behaviors. React documents static getDerivedStateFromError(error) as the mechanism for updating state so a boundary can render fallback UI; componentDidCatch(error, info) is available for side effects such as logging. The info.componentStack value provides component ancestry that can help identify where the failure occurred (React component reference).
Inject a reporter, mock, or test adapter into the boundary and verify the reporting contract independently from the fallback assertion. For example, check that it receives the same error instance or expected message, along with useful component-stack or application context. Avoid coupling the test to incidental formatting of a full stack unless that format is itself part of your integration contract.
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.
- Fallback test: Does the user see the expected recovery UI?
- Reporting test: Does the configured reporter receive the error and useful context?
Do not use window.onerror as the only proof that a caught error was reported. React documents different bubbling behavior in development and production: development errors may bubble to window, while in production errors caught by componentDidCatch do not bubble to ancestor handlers. The boundary should explicitly call the reporting integration, and the test should verify that call.
What error boundaries catch—and what they do not
An error boundary handles errors thrown while rendering descendants in the part of the component tree it encloses. It does not catch every JavaScript error associated with that UI. React lists these important limits:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Rank #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.
- Event handlers: invoke the handler in a test and check its own catch, reporting, or application behavior; do not expect the boundary fallback just because the handler throws.
- Asynchronous callbacks: errors from callbacks such as
setTimeoutorrequestAnimationFrameneed their own handling and tests. - Server rendering: server-rendering errors are outside the boundary’s client-side recovery behavior.
- The boundary itself: a boundary cannot catch an error in its own rendering or reporting path; test that failure at a higher layer.
React documents an exception for errors thrown inside the function returned by useTransition’s startTransition. Do not generalize that exception to arbitrary asynchronous work. Test each non-render path by triggering that path and asserting its actual error handling or reporting behavior.
React 18 and React 19: callbacks and console output
Use the render options supported by the React and Testing Library versions in your project. Testing Library documents extended console output for boundary errors in both versions, but the console method differs; React 19 also exposes caught and recoverable error callbacks through its render API.
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
| Behavior | React 18 | React 19 |
|---|---|---|
| Extended boundary diagnostic documented by Testing Library | console.error |
console.warn |
onCaughtError render option |
Unsupported, according to the Testing Library FAQ | Available in the documented API for errors caught by a boundary |
onRecoverableError render option |
Use only if supported by the installed API; check your project’s version-specific documentation | Available in the documented API for errors React automatically recovers from |
legacyRoot render option |
For React 18 and earlier, according to the Testing Library API | Not for React 19 |
These framework diagnostics can make a passing test look noisy. If you suppress console output, spy on only the relevant method, limit suppression to the test that needs it, and restore the spy afterward. For React 19, Testing Library documents using the onCaughtError render option when you intentionally observe caught errors or need to suppress the extra warning. That option is not supported in React 18 (Testing Library FAQ; React Testing Library API).
When a test needs to inspect root-level error handling, treat each callback as a separate contract: onCaughtError concerns an error caught by a boundary, while onRecoverableError concerns an error React automatically recovered from. Neither replaces the user-facing fallback assertion or a test of an explicitly injected boundary reporter.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →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.
Boundary-level reporting or React 19 root callbacks?
These mechanisms cover different integration points rather than offering a universal either-or choice.
| Approach | Useful for | Test focus |
|---|---|---|
Boundary-level componentDidCatch |
Reporting a failure at the boundary that owns the fallback | Verify the boundary’s reporter receives the error and component information |
| React 19 root callbacks | Observing caught, uncaught, or recoverable errors at the React root | Verify the specific callback and payload for the path being exercised |
Sentry’s June 17, 2024 release note for version 8.6.0 of its React and Next.js SDKs describes React 19 support for new error-handling hooks. It describes attaching Sentry.reactErrorHandler to root onUncaughtError, onCaughtError, and onRecoverableError callbacks, and says component stacks are attached to new errors (Sentry React 19 support). That release note is version- and date-specific; check current Sentry documentation and the behavior of your installed SDK before adopting its integration pattern.
Choose a boundary scope that matches the fallback
A boundary should enclose a meaningful area for which a shared recovery UI makes sense. React says there is no need to wrap every component: a conversation list or an individual message may be useful scopes, while a single avatar is generally too fine-grained. Test the boundary at the same scope your application intends to protect, including what remains visible around its fallback.
React’s documented boundary implementation uses a class component. React says there is not currently a direct function-component implementation; an application can reuse a class boundary or use a boundary library such as react-error-boundary. The test pattern stays the same: cause a descendant render failure, assert visible fallback behavior, and check reporting separately.
Recommended Free Tools
Route-level boundaries
Routing errors may have their own boundary mechanism. React Router sends an error to the nearest route error boundary, and recommends a root boundary as minimum coverage. Trigger the route loader, action, or component error relevant to your route and assert the closest route boundary’s UI and route-specific state. Form validation is a separate concern, as is dedicated error reporting; a route fallback assertion alone does not test either (React Router error boundaries).
Quick Recap
A practical coverage checklist
| Scenario | Trigger | Assert |
|---|---|---|
| Boundary fallback | A descendant throws during rendering | Fallback content or accessible alert is visible |
| Reporting side effect | The same deterministic render failure | Reporter receives the error and useful component context |
| Missing or ineffective boundary | Render a throwing child without an enclosing boundary | Render failure is surfaced; do not assert a fallback |
| Event-handler failure | Invoke the handler that throws | Handler-level handling, reporting, or resulting application behavior |
| Asynchronous failure | Trigger the timer, callback, or workflow | Its own error-handling or reporting path |
| Failure inside the boundary | Make the boundary’s own render or reporting path fail | Handling at a higher layer |
| React 19 root callback | Exercise the caught, uncaught, or recoverable path | The appropriate callback and payload, separately from fallback UI |
| Route error | Trigger a route loader, action, or component error | The closest 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.




