Skip to content
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

docs: add a note on when not to use renderHook #1093

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion docs/react-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ react supports `act`. It is recommended to use the import from

This is a convenience wrapper around `render` with a custom test component. The
API emerged from a popular testing pattern and is mostly interesting for
libraries publishing hooks. You should prefer `render` since a custom test
libraries publishing hooks.

Do not use `renderHook` when your hook is easy to test by just testing the components using it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Do not use `renderHook` when your hook is easy to test by just testing the components using it.
Do not use `renderHook` when your hook can be easily tested by testing the components using it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @zaicevas!
A minor suggestion here.

Alternatively, you should prefer `render` since a custom test
Copy link
Member

Choose a reason for hiding this comment

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

Is "alternatively" really needed here? I think we can remove it :)

component results in more readable and robust tests since the thing you want to
test is not hidden behind an abstraction.

Expand Down