mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
/* eslint react/no-render-return-value: 0 */
|
|
import _ from 'underscore';
|
|
import ReactDOM from "react-dom";
|
|
import ReactTestUtils from 'react-addons-test-utils';
|
|
|
|
export function scryRenderedComponentsWithTypeAndProps(root, type, props) {
|
|
if (!root) { throw new Error("Must supply a root to scryRenderedComponentsWithTypeAndProps"); }
|
|
return _.compact(_.map(ReactTestUtils.scryRenderedComponentsWithType(root, type), (el) => {
|
|
if (_.isEqual(_.pick(el.props, Object.keys(props)), props)) {
|
|
return el;
|
|
}
|
|
return false;
|
|
}));
|
|
}
|
|
|
|
let ReactElementContainers = [];
|
|
// Override ReactTestUtils.renderIntoDocument so that
|
|
// we can remove all the created elements after the test completes.
|
|
export function renderIntoDocument(element) {
|
|
const container = document.createElement('div');
|
|
ReactElementContainers.push(container);
|
|
return ReactDOM.render(element, container);
|
|
}
|
|
|
|
export function unmountAll() {
|
|
for (let i = 0; i < ReactElementContainers.length; i++) {
|
|
const container = ReactElementContainers[i];
|
|
ReactDOM.unmountComponentAtNode(container);
|
|
}
|
|
ReactElementContainers = [];
|
|
}
|