react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

feat: Add support for React error handlers

Open eps1lon opened this issue 1 year ago • 1 comments

What:

Alternate to https://github.com/testing-library/react-testing-library/pull/1333

Adds support for onRecoverableError and onCaughtError (React 19 only)

onUncaughtError is not supported yet because there's no use. The render would throw anyway. We're likely going to change that though in React.

Why:

This allows test setups that fail on console errors to silence specific, expected errors in their tests. Especially onCaughtError will simplify testing of error boundaries since it will disable React's default console.error + window.onError dispatch (see docs I'll add soon)

How:

Forward mentioned options to React's createRoot call.

Checklist:

  • [x]Documentation added to the docs site: https://github.com/testing-library/testing-library-docs/pull/1424
  • [x] Tests
  • [x] TypeScript definitions updated
  • [x] Ready to be merged

eps1lon avatar Aug 28 '24 20:08 eps1lon