From ca4467a2e908bd900aa260a4cf2f0f04ae40df9d Mon Sep 17 00:00:00 2001 From: Eduardo Rabelo Date: Sun, 5 May 2019 01:20:03 +1000 Subject: [PATCH] feat: add custom container target (#12) * add custom container target * using default params * addressing comment "pull/12#discussion_r280982845" --- src/index.js | 4 ++-- tests/render.spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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() + }) })