import React from 'react' ; import { render } from 'design/utils/testing' ; import Portal from './Portal' ; describe ( 'design/Modal/Portal' , ( ) => { test ( 'container to be attached to body element' , ( ) => { const { getByTestId , container } = renderPortal ( ) ; const content = getByTestId ( 'content' ) ; expect ( container ) . not . toContainElement ( content ) ; expect ( content . parentNode . nodeName ) . toBe ( 'BODY' ) ; } ) ; test ( 'container to be attached to custom element' , ( ) => { const customElement = document . createElement ( 'div' ) ; const { queryByTestId } = renderPortal ( { container : customElement } ) ; expect ( queryByTestId ( 'content' ) ) . not . toBeInTheDocument ( ) ; expect ( customElement ) . toHaveTextContent ( 'hello' ) ; } ) ; test ( 'disable the portal behavior' , ( ) => { const { getByTestId , container } = renderPortal ( { disablePortal : true } ) ; expect ( container ) . toContainElement ( getByTestId ( 'content' ) ) ; } ) ; } ) ; function renderPortal ( props ) { return render ( < div data - testid = "parent" > < Portal { ... props } > < div data - testid = "content" > hello < /div> < /Portal> < /div>); }