File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 11import React from 'react'
2- import { render } from '@testing-library/react'
2+ import { render , within } from '@testing-library/react'
33import { Modal } from '../modal'
44
55test ( 'modal shows the children' , ( ) => {
6- const { getByText } = render (
6+ render (
77 < Modal >
8- < div > test</ div >
8+ < div data-testid = " test" / >
99 </ Modal > ,
1010 )
11- expect ( getByText ( 'test' ) ) . toBeInTheDocument ( )
11+ const { getByTestId} = within ( document . getElementById ( 'modal-root' ) )
12+ expect ( getByTestId ( 'test' ) ) . toBeInTheDocument ( )
1213} )
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ if (!modalRoot) {
1212// you need to think about accessibility and styling.
1313// Look into: https://ui.reach.tech/dialog
1414function Modal ( { children} ) {
15- const el = React . useRef ( document . createElement ( 'el ' ) )
15+ const el = React . useRef ( document . createElement ( 'div ' ) )
1616 React . useLayoutEffect ( ( ) => {
1717 const currentEl = el . current
1818 modalRoot . appendChild ( currentEl )
You can’t perform that action at this time.
0 commit comments