Skip to content

Commit

Permalink
feat: add custom container target (#12)
Browse files Browse the repository at this point in the history
* add custom container target

* using default params

* addressing comment "pull/12#discussion_r280982845"
  • Loading branch information
oieduardorabelo authored and benmonro committed May 4, 2019
1 parent 059db11 commit ca4467a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {getQueriesForElement, prettyDOM} from 'dom-testing-library'

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

const component = new Component({
...options,
Expand Down
15 changes: 15 additions & 0 deletions tests/render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ describe('render', () => {

expect(global.console.log).toHaveBeenCalledWith(prettyDOM(document.body))
})

test('custom container target', () => {
const customTarget = document.createElement('main')
customTarget.dataset.testid = 'custom-target'

document.body.appendChild(customTarget)

const {getByText, getByTestId} = render(App, {
target: customTarget,
props: {name: 'world'},
})

expect(getByText('Hello world!')).toBeInTheDocument()
expect(getByTestId('custom-target')).toBeInTheDocument()
})
})

0 comments on commit ca4467a

Please sign in to comment.