Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

‎src/index.js‎

Lines changed: 2 additions & 2 deletions
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-
consttarget=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,

‎tests/render.spec.js‎

Lines changed: 15 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /