Skip to content

Commit 0256697

Browse files
author
Kent C. Dodds
committed
fix modal
1 parent 90ead67 commit 0256697

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/__tests__/portals.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react'
2-
import {render} from '@testing-library/react'
2+
import {render, within} from '@testing-library/react'
33
import {Modal} from '../modal'
44

55
test('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
})

src/modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
1414
function 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)

0 commit comments

Comments
 (0)