diff --git a/src/index.js b/src/index.js index fabf240..450b82f 100644 --- a/src/index.js +++ b/src/index.js @@ -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, diff --git a/tests/render.spec.js b/tests/render.spec.js index ecf9634..8f209be 100644 --- a/tests/render.spec.js +++ b/tests/render.spec.js @@ -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() + }) })