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

fix: add support for react portal elements #107

Merged
merged 4 commits into from
Jun 12, 2018

Conversation

spichen
Copy link
Contributor

@spichen spichen commented Jun 6, 2018

What:
Components like modals, dialogs, hovercards, tooltips etc use React portals to render them into document.body. Testing utilities can query only on the container and this cannot do testing in such components.

Why:
This fix is necessary to test components that uses react portals.

How:
When using renderIntoComponent, instead of exposing test utilities for container, we do it for document.body which contains the container.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

@kentcdodds
Copy link
Member

This is very interesting! I'm leaning on accepting these changes but would like to hear what others have to say about it...

@gnapse
Copy link
Member

gnapse commented Jun 6, 2018

To add some context, #62 has a discussion about how this is possible today with some workaround (probably similar to what this PR brings out-of-the-box, haven't made a thorough comparison).

@kentcdodds
Copy link
Member

Perhaps we could expose some additional queries on a namespace:

const {inBody} = renderIntoDocument(<Stuff />)
const submitButton = inBody.getByText('Submit')

@kentcdodds
Copy link
Member

But I'm not sure I like that either. I'm thinking the solution in #62 is very straightforward and prefer that over bloating the API further. Use cases for portals are few and far between so I don't think it's worth the extra overhead.

@spichen
Copy link
Contributor Author

spichen commented Jun 7, 2018

I'd prefer not to bloat the API for this. By documentation, renderIntoDocument says it render into document.body. So I hope just exposing test queries on document.body is meaningful here.

@kentcdodds
Copy link
Member

That makes sense to me. Ok, I'm in favor of this change. Let's make a change to the docs to explain this as well.

@kentcdodds kentcdodds merged commit f58dfa1 into testing-library:master Jun 12, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 3.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this pull request Jul 26, 2020
…tton-click

fix: 🐛 don't fire events when clicking disabled radio button
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.

3 participants