From e6ac5ad9977b81619ddf1e7cbdeb98cf553c82a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 3 Oct 2018 20:21:20 +0200 Subject: [PATCH] pass options to renderer; add update & unmount, rm instance & renderer --- src/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 86857ddb..3f019ca1 100644 --- a/src/index.js +++ b/src/index.js @@ -26,17 +26,18 @@ export const flushMicrotasksQueue = (): Promise => * Renders test component deeply using react-test-renderer and exposes helpers * to assert on the output. */ -export const render = (component: React.Element<*>) => { - const renderer = TestRenderer.create(component); +export const render = ( + component: React.Element<*>, + options?: { createNodeMock: (element: React.Element<*>) => any } +) => { + const renderer = TestRenderer.create(component, options); const instance = renderer.root; return { - instance, - renderer, getByTestId: (testID: string) => instance.findByProps({ testID }), - getByName: (name: string) => + getByName: (name: string | React.Element<*>) => instance.find(node => getNodeByName(node, name)), - getAllByName: (name: string) => + getAllByName: (name: string | React.Element<*>) => instance.findAll(node => getNodeByName(node, name)), getByText: (text: string | RegExp) => instance.find(node => getNodeByText(node, text)), @@ -46,6 +47,8 @@ export const render = (component: React.Element<*>) => { instance.findByProps(props), getAllByProps: (props: { [propName: string]: any }) => instance.findAllByProps(props), + update: renderer.update, + unmount: renderer.unmount, }; };