-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
30 lines (25 loc) · 1.03 KB
/
helpers.js
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
26
27
28
29
30
import { cloneElement } from 'react';
import ReactDOM from 'react-dom';
export function shouldWarn(about) {
console.error.expected.push(about); // eslint-disable-line no-console
}
/**
* Helper for rendering and updating props for plain class Components
* since `setProps` is deprecated.
* @param {ReactElement} element Root element to render
* @param {HTMLElement?} mountPoint Optional mount node, when empty it uses an unattached div like `renderIntoDocument()`
* @return {ComponentInstance} The instance, with a new method `renderWithProps` which will return a new instance with updated props
*/
export function render(element, mountPoint) {
let mount = mountPoint || document.createElement('div');
let instance = ReactDOM.render(element, mount);
if (instance && !instance.renderWithProps) {
instance.renderWithProps = newProps =>
render(cloneElement(element, newProps), mount);
}
return instance;
}
export function getOne(collection) {
expect(collection.length).to.equal(1);
return collection[0];
}