-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathshallowRenderHelper.js
More file actions
25 lines (23 loc) · 926 Bytes
/
shallowRenderHelper.js
File metadata and controls
25 lines (23 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Function to get the shallow output for a given component
* As we are using phantom.js, we also need to include the fn.proto.bind shim!
*
* @see http://simonsmith.io/unit-testing-react-components-without-a-dom/
* @author somonsmith
*/
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import ShallowRenderer from 'react-test-renderer/shallow'
/**
* Get the shallow rendered component
*
* @param {Object} component The component to return the output for
* @param {Object} props [optional] The components properties
* @param {Mixed} ...children [optional] List of children
* @return {Object} Shallow rendered output
*/
export default function createComponent(component, props = {}, ...children) {
const renderer = new ShallowRenderer();
renderer.render(React.createElement(component, props, children.length > 1 ? children : children[0]));
return renderer.getRenderOutput();
}