react-toolbox/components/utils/testing.js

20 lines
604 B
JavaScript
Raw Permalink Normal View History

import React from 'react';
import TestUtils from 'react-dom/test-utils';
2015-09-05 22:34:16 +03:00
export default {
2017-01-26 20:05:32 +03:00
renderComponent(Component, props = {}, state = {}) {
const component = TestUtils.renderIntoDocument(<Component {...props} />);
2015-09-05 22:34:16 +03:00
if (state !== {}) { component.setState(state); }
return component;
},
2017-01-26 20:05:32 +03:00
shallowRenderComponent(component, props, ...children) {
const shallowRenderer = TestUtils.createRenderer();
2017-01-28 15:16:31 +03:00
shallowRenderer.render(React.createElement(component, props, children.length > 1
2017-01-26 20:05:32 +03:00
? children
: children[0],
2017-01-28 15:16:31 +03:00
));
return shallowRenderer.getRenderOutput();
2017-01-26 20:05:32 +03:00
},
2015-09-05 22:34:16 +03:00
};