Skip to content

How to check existence of portalled elements with testing libraries? #1130

Answered by imshubhamsingh
seedy asked this question in Help
Discussion options

You must be logged in to vote

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}</>;
  }),
}));

Replies: 3 comments 16 replies

Comment options

You must be logged in to vote
6 replies
@vorillaz
Comment options

@seedy
Comment options

@seedy
Comment options

@vorillaz
Comment options

@seedy
Comment options

Comment options

You must be logged in to vote
10 replies
@JanderSilv
Comment options

@djalmaaraujo
Comment options

@josephadd
Comment options

@hallucinogenizer
Comment options

@wa1id
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by seedy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet