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

feat: add render hook support for multiple arguments

Open imevanc opened this issue 9 months ago • 5 comments

What: Add render hook support for multiple arguments

Why: renderHook only supports a single argument via initialProps, making it hard to test hooks with multiple parameters. This PR introduces initialArgs to allow passing multiple arguments directly, improving flexibility and reducing workarounds.

How:

  1. Added initialArgs support → Spreads arguments into the hook.
  2. Updated rerender → Now accepts multiple parameters.
  3. Ensured backward compatibility → initialProps remains unchanged.
  4. Throws an error if both initialProps and initialArgs are used.
  5. Added tests & updated docs → Validates behavior and documents usage.

Issue: https://github.com/testing-library/react-testing-library/issues/1350

Checklist:

  • [ ] Documentation added to the docs site
  • [x] Tests
  • [x] TypeScript definitions updated
  • [x] Ready to be merged

imevanc avatar Mar 12 '25 22:03 imevanc

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 42c12ac19cc7d984d5fcaaee133202861880bb42:

Sandbox Source
react-testing-library-examples Configuration

codesandbox-ci[bot] avatar Mar 12 '25 22:03 codesandbox-ci[bot]

@eps1lon - awaiting your feedback 🧑‍💻

imevanc avatar Mar 12 '25 23:03 imevanc

@danielrentz - anything to add ?

imevanc avatar Mar 14 '25 21:03 imevanc

@Hardanish-Singh - just rebased, can you please thumb it again?

imevanc avatar Mar 21 '25 22:03 imevanc

@imevanc @Hardanish-Singh the typings are still broken

danielrentz avatar Mar 24 '25 05:03 danielrentz