import React, { useEffect, useRef, useState } from 'react' import { render, waitFor } from '@testing-library/react' import { Popover, useFloating, type PopoverProps } from './' const PopoverWrapper = (customProps?: Partial): JSX.Element => { const { refs } = useFloating() return ( Hello ) } describe('', () => { describe('Portals', () => { const PopoverWrapperWithPortal = ({ shouldUsePortal = false, }: { shouldUsePortal?: boolean }): JSX.Element => { const portalRef = useRef(null) const [portalContainer, setPortalContainer] = useState() useEffect(() => { if (portalRef.current !== null) { setPortalContainer(portalRef.current) } }, []) return ( <>
) } it('renders within portal container', async () => { const { getByTestId } = render() await waitFor(() => { expect(getByTestId('portal-container')).toHaveTextContent('Hello') }) }) it('renders in document.body by default', async () => { const { getByTestId } = render() await waitFor(() => { expect(document.body).toHaveTextContent('Hello') expect(getByTestId('portal-container')).not.toHaveTextContent('Hello') }) }) }) })