Skip to content

feat: forward all render options through renderHook#83

Open
greymoth-jp wants to merge 1 commit into
testing-library:mainfrom
greymoth-jp:fix-renderhook-forward-options
Open

feat: forward all render options through renderHook#83
greymoth-jp wants to merge 1 commit into
testing-library:mainfrom
greymoth-jp:fix-renderhook-forward-options

Conversation

@greymoth-jp

Copy link
Copy Markdown

renderHook only pulls wrapper out of its options and passes { wrapper } on to render, so the rest of the render options (container, baseElement, queries) get silently dropped. For example renderHook(cb, { container }) has no effect — the hook still mounts into a freshly created container under document.body.

@testing-library/react started out with the same shape and changed it in testing-library/react-testing-library#1118 to spread the remaining options straight through:

const { initialProps, ...renderOptions } = options
// ...
render(<TestComponent ... />, renderOptions)

This does the same thing here, so renderHook accepts the same render options as render.

I added a test that passes a custom container and checks the wrapper actually renders into it — without the change it fails (the marker ends up in the auto-created container instead). The rest of the suite stays green (105 tests).

Kept this to the runtime only and left the RenderHookOptions type alone, since #82 is already touching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant