Skip to content

BREAKING: bind queries to the container #262

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

Conversation

adams-brian
Copy link

What:

Bug fix: bind queries to the container in render

Why:

The docs state that "the most important feature of render is that the queries from dom-testing-library are automatically returned with their first argument bound to the rendered container".

But if no container was passed to render, the queries it was returning were bound to document.body (code here and here).

How:

This PR ensures the queries are bound to the container, adds a corresponding unit test, and fixes an older unit test that was only passing because the queries were being incorrectly bound to document.body.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Additional comments

Bug was found while responding to this StackOverflow issue

@alexkrolick alexkrolick changed the title bind queries to the container BREAKING: bind queries to the container Jan 11, 2019
@alexkrolick
Copy link
Collaborator

alexkrolick commented Jan 11, 2019

  1. The current behavior is actually intentional to support querying Portals and other elements that render outside the root node. The docs could be rephrased to reflect this. Querying elements does provide unexpected behavior  #254 (comment)
  2. This would be a breaking change. If accepted we would need to add docs to explain how to use within() or unbound dom-testing queries to test modals, etc.

Suggested change:

the most important feature of render is that the queries from dom-testing-library are automatically returned with their first argument bound to the document

@kentcdodds
Copy link
Member

Hi @brian-lives-outdoors,

Thanks for the PR, but we will not be making this change. As @alexkrolick mentioned, this is intentional.

If you need this for some reason, then it's likely that you aren't cleaning up the document properly. Make sure to you're using cleanup (or import 'react-testing-library/cleanup-after-each).

Thanks again!

@kentcdodds kentcdodds closed this Jan 11, 2019
@kentcdodds
Copy link
Member

That said, we would accept a PR to the docs to make them more clear here!

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this pull request Jul 26, 2020
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