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

#9 - add custom container target #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
benmonro merged 3 commits into testing-library:master from oieduardorabelo:master
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.js
View file Open in desktop
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
View file Open in desktop
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()
})
})

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