Skip to content

Update docs with reactStrictMode in render #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/react-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ as these methods:
- [`onRecoverableError`](#onrecoverableerror)
- [`wrapper`](#wrapper)
- [`queries`](#queries)
- [`reactStrictMode`](#render-options-reactstrictmode)
- [`render` Result](#render-result)
- [`...queries`](#queries-1)
- [`container`](#container-1)
Expand All @@ -31,7 +32,8 @@ as these methods:
- [`initialProps`](#initialprops)
- [`onCaughtError`](#oncaughterror)
- [`onRecoverableError`](#onrecoverableerror)
- [`wrapper`](#wrapper-1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link was wrong

- [`wrapper`](#renderhook-options-wrapper)
- [`reactStrictMode`](#renderhook-options-reactstrictmode)
- [`renderHook` Result](#renderhook-result)
- [`result`](#result)
- [`rerender`](#rerender-1)
Expand Down Expand Up @@ -161,6 +163,11 @@ utility functions to create custom queries.
Custom queries can also be added globally by following the
[custom render guide](setup.mdx#custom-render).

### `render` Options `reactStrictMode`
Copy link
Member

@eps1lon eps1lon Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### `render` Options `reactStrictMode`
### `reactStrictMode`

Isn't this redundant? Also don't forget to update the anchor if you accept the change.

Copy link
Contributor Author

@bernardobelchior bernardobelchior Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming it only reactStrictMode would conflict with reactStrictMode from configure because they would share the same hash. If you prefer another name, let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nested below "render Options" already so there shouldn't be a conflict. Or do you mean the anchors conflict? Can we decouple the anchor ID from the heading name?

This just seems noisy at the moment:

- render Options
   - container
   - baseElement
   - [...]
   - render Options reactStrictMode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the anchors conflict?

Exactly.

Can we decouple the anchor ID from the heading name?

It seems auto-generated. How would you suggest we do that?

This just seems noisy at the moment:

Yeah, I agree, but I was following the same pattern as renderHook Options wrapper.

Happy to change, but I'm not sure if there's an easy solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's keep it for now. Could even argue the repeated context is good on nested list with lots of siblings since it reduces cognitive overhead.


When enabled, [`<StrictMode>`](https://react.dev/reference/react/StrictMode) is rendered around the inner element.
If defined, overrides the value of `reactStrictMode` set in [`configure`](https://testing-library.com/docs/react-testing-library/api/#configure-options).

## `render` Result

The `render` method returns an object that has a few properties:
Expand Down Expand Up @@ -431,6 +438,11 @@ Behaves the same as [`onRecoverableError` in `ReactDOMClient.createRoot`](https:

See [`wrapper` option for `render`](#wrapper)


### `renderHook` Options `reactStrictMode`

See [`reactStrictMode` option for `render`](#render-options-reactstrictmode)

## `renderHook` Result

The `renderHook` method returns an object that has a few properties:
Expand Down Expand Up @@ -503,3 +515,5 @@ configure({reactStrictMode: true})

When enabled, [`<StrictMode>`](https://react.dev/reference/react/StrictMode) is
rendered around the inner element. Defaults to `false`.

This setting can be changed for a single test by providing `reactStrictMode` in the options argument of the [`render`](#render-options-reactstrictmode) function.