You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
renderedComponent.container is an empty div in that case. The portal/modal rendered in the document.body and all the queries were generated from the base element which, in the latest version is baseElement = document.documentElement. So all the queries behave as expected, as they look inside documentElement, but the container is an empty div.
So, when we don't pass document.body as container to the render method, which I believe is to avoid the warnings around the rendering directly in div. The render just returns an empty div as container.
render method, if not passed a container, returns container by creating a div element in the body. It works fine for all the portal less components which don't render anything in the body. But for the components which create portals and render those in the document.body, the container doesn't include all the rendered DOM. If we are just testing a modal box, e.g., then the container will just be empty.
Suggested solution:
I have two possible solutions in mind.
return baseElement as well from the render
make the container same as baseElement and return that
The text was updated successfully, but these errors were encountered:
ekafeel
changed the title
Render returns empty div as container when passed a portal/modal as component
Render returns empty div as container when passed a portal/modal as component
Jun 26, 2018
react-testing-library
4.0.2:react
16.3.2:node
8.10.0:npm
5.6.0:Relevant code or config:
What you did:
What happened:
renderedComponent.container
is an empty div in that case. The portal/modal rendered in the document.body and all the queries were generated from the base element which, in the latest version isbaseElement = document.documentElement
. So all the queries behave as expected, as they look inside documentElement, but the container is an empty div.Reproduction:
sandbox url: https://codesandbox.io/s/k98yl70j27
Problem description:
So, when we don't pass
document.body
as container to therender
method, which I believe is to avoid the warnings around the rendering directly in div. Therender
just returns an empty div as container.render
method, if not passed a container, returns container by creating a div element in the body. It works fine for all the portal less components which don't render anything in the body. But for the components which create portals and render those in thedocument.body
, the container doesn't include all the rendered DOM. If we are just testing a modal box, e.g., then the container will just be empty.Suggested solution:
I have two possible solutions in mind.
baseElement
as well from the renderbaseElement
and return thatThe text was updated successfully, but these errors were encountered: