forked from adazzle/react-data-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropTestUtils.js
49 lines (39 loc) · 1.19 KB
/
PropTestUtils.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* @flow */
/** @jsx dom */
'use strict';
var React = require('react');
var ReactDOM = require('react-dom');
class PropTestUtils {
constructor(klass, props, container, callback) {
this.klass = klass;
this.container = container || document.createElement('div');
this.props = props || {};
this.render(callback);
}
render(callback) {
var element = React.createElement(this.klass, this.props);
this.component = ReactDOM.render(element, this.container, callback);
}
replaceProps(props, callback) {
this.props = {};
this.setProps(props, callback);
}
setProps(partialProps, callback) {
if (this.klass == null) {
console.warn(
'setProps(...): Can only update a mounted or ' +
'mounting component. This usually means you called setProps() on ' +
'an unmounted component. This is a no-op.'
);
return;
}
Object.assign(this.props, partialProps);
var element = React.createElement(this.klass, this.props);
this.component = ReactDOM.render(element, this.container, callback);
}
unmount() {
ReactDOM.unmountComponentAtNode(this.container);
this.klass = null;
}
}
module.exports = PropTestUtils;