Replies: 3 comments 16 replies
-
Hey there, you can use the container option upon rendering the dropdown component const {container} = render(<Dropdown {...props} />, {
container: document.body,
}); |
Beta Was this translation helpful? Give feedback.
6 replies
-
Hey! Facing same problem, did you solve how to get access portal in tests ? |
Beta Was this translation helpful? Give feedback.
10 replies
-
Mocking the portal worked for me for Dialog and dropdown. We just wanted to check the functionality of the component as to what all get renders inside portal. Below is the mock: import { forwardRef } from "react";
import { PortalProps } from "@radix-ui/react-portal";
jest.mock("@radix-ui/react-portal", () => ({
...jest.requireActual("@radix-ui/react-portal"),
Portal: forwardRef<HTMLDivElement, PortalProps>(function PortalMock(props, ref) {
return <>{props.children}</>;
}),
})); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, folks! Hope you're doing well 👋
I'm using Testing-Library/React to perform integration tests in my application.
I would need to validate some internal rules where some user permissions impact what's rendered inside a
DropdownMenuContent
.I need to have it
portalled
for my UI.I don't use the portal utility yet.
In my DOM, I have a
<div data-radix-portal >
node at the end of mybody
, where I can see theDropdownMenuContent
mounts when opened.Hence I would have expected to look for it in my tests to find any portalled element.
I noticed that the
<div data-radix-portal >
node is not rendered inside my testing environment, I was wondering if you had clues about the why?Repro
Here's my simplest repro as of now:
Logs
Also, what would be the best practice you'd recommend to properly manage portals inside tests?
A few moments Later...
Portal's implementation here
This specific line made me wonder whether my testing environment doesn't follow the expected structure 😕
jest.spyOn
ReactDOM.createPortal
, I see no call to it.globalThis?.document?.body
, I see it is exactly equal todocument.body
Test
Logs
Beta Was this translation helpful? Give feedback.
All reactions