Skip to content

Commit ca4467a

Browse files
oieduardorabelobenmonro
authored andcommitted
feat: add custom container target (#12)
* add custom container target * using default params * addressing comment "pull/12#discussion_r280982845"
1 parent 059db11 commit ca4467a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {getQueriesForElement, prettyDOM} from 'dom-testing-library'
22

33
export * from 'dom-testing-library'
44
const mountedContainers = new Set()
5-
export const render = (Component, options) => {
6-
const target = document.body.appendChild(document.createElement('div'))
5+
export const render = (Component, {target = document.createElement('div'), ...options} = {}) => {
6+
document.body.appendChild(target)
77

88
const component = new Component({
99
...options,

Diff for: tests/render.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ describe('render', () => {
4646

4747
expect(global.console.log).toHaveBeenCalledWith(prettyDOM(document.body))
4848
})
49+
50+
test('custom container target', () => {
51+
const customTarget = document.createElement('main')
52+
customTarget.dataset.testid = 'custom-target'
53+
54+
document.body.appendChild(customTarget)
55+
56+
const {getByText, getByTestId} = render(App, {
57+
target: customTarget,
58+
props: {name: 'world'},
59+
})
60+
61+
expect(getByText('Hello world!')).toBeInTheDocument()
62+
expect(getByTestId('custom-target')).toBeInTheDocument()
63+
})
4964
})

0 commit comments

Comments
 (0)