Skip to content

Commit

Permalink
revert: #11ffbf365222eeb348cc14345fffd88fca6855f9 (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored Sep 13, 2024
1 parent 941c8e3 commit f302be9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
24 changes: 0 additions & 24 deletions docs/react-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ as these methods:
- [`baseElement`](#baseelement)
- [`hydrate`](#hydrate)
- [`legacyRoot`](#legacyroot)
- [`onCaughtError`](#oncaughterror)
- [`onRecoverableError`](#onrecoverableerror)
- [`wrapper`](#wrapper)
- [`queries`](#queries)
- [`render` Result](#render-result)
Expand All @@ -29,8 +27,6 @@ as these methods:
- [`renderHook`](#renderhook)
- [`renderHook` Options](#renderhook-options)
- [`initialProps`](#initialprops)
- [`onCaughtError`](#oncaughterror)
- [`onRecoverableError`](#onrecoverableerror)
- [`wrapper`](#wrapper-1)
- [`renderHook` Result](#renderhook-result)
- [`result`](#result)
Expand Down Expand Up @@ -124,16 +120,6 @@ React 17 (i.e.
[`ReactDOM.render`](https://react.dev/reference/react-dom/render)) then you
should enable this option by setting `legacyRoot: true`.

### `onCaughtError`

Callback called when React catches an error in an Error Boundary.
Behaves the same as [`onCaughtError` in `ReactDOMClient.createRoot`](https://react.dev/reference/react-dom/client/createRoot#parameters).

### `onRecoverableError`

Callback called when React automatically recovers from errors.
Behaves the same as [`onRecoverableError` in `ReactDOMClient.createRoot`](https://react.dev/reference/react-dom/client/createRoot#parameters).

### `wrapper`

Pass a React Component as the `wrapper` option to have it rendered around the
Expand Down Expand Up @@ -417,16 +403,6 @@ test('returns logged in user', () => {
> }
> ```
### `onCaughtError`

Callback called when React catches an error in an Error Boundary.
Behaves the same as [`onCaughtError` in `ReactDOMClient.createRoot`](https://react.dev/reference/react-dom/client/createRoot#parameters).

### `onRecoverableError`

Callback called when React automatically recovers from errors.
Behaves the same as [`onRecoverableError` in `ReactDOMClient.createRoot`](https://react.dev/reference/react-dom/client/createRoot#parameters).

### `renderHook` Options `wrapper`
See [`wrapper` option for `render`](#wrapper)
Expand Down
51 changes: 0 additions & 51 deletions docs/react-testing-library/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,57 +81,6 @@ as part of the `change` method call.

<details>

<summary>How do I test error boundaries</summary>

To test if an error boundary successfully catches an error, you should make sure that the fallback of the boundary is displayed when a child threw.

Here's an example of how you can test an error boundary:

```jsx
import React from 'react'
import {render, screen} from '@testing-library/react'

class ErrorBoundary extends React.Component {
state = {error: null}
static getDerivedStateFromError(error) {
return {error}
}
render() {
const {error} = this.state
if (error) {
return <div>Something went wrong</div>
}
return this.props.children
}
}

test('error boundary catches error', () => {
const {container} = render(
<ErrorBoundary>
<BrokenComponent />
</ErrorBoundary>,
)
expect(container.textContent).toEqual('Something went wrong.')
})
```

If the error boundary did not catch the error, the test would fail since the `render` call would throw the error the Component produced.


:::info

React 18 will call `console.error` with an extended error message.
React 19 will call `console.warn` with an extended error message.

To disable the additional `console.warn` call in React 19, you can provide a custom `onCaughtError` callback e.g. `render(<App />, {onCaughtError: () => {}})`
`onCaughtError` is not supported in React 18.

:::

</details>

<details>

<summary>Can I write unit tests with this library?</summary>

Definitely yes! You can write unit and integration tests with this library. See
Expand Down

0 comments on commit f302be9

Please sign in to comment.