Support ReactTestUtils.mockComponent.
Ben Newman committed
Jan 2, 2014 at 18:31 UTC
a00e4c840c2d270ea1fce886b9195e8cd18fb24c
1 file changed
+23
src/test/ReactTestUtils.js
+23
@@ -19,11 +19,13 @@
19
var EventConstants = require('EventConstants');
20
var React = require('React');
21
var ReactComponent = require('ReactComponent');
22
+var ReactDOM = require('ReactDOM');
23
var ReactEventEmitter = require('ReactEventEmitter');
24
var ReactTextComponent = require('ReactTextComponent');
25
var ReactMount = require('ReactMount');
26
27
var mergeInto = require('mergeInto');
28
+var copyProperties = require('copyProperties');
29
30
var topLevelTypes = EventConstants.topLevelTypes;
31
@@ -190,6 +192,27 @@ var ReactTestUtils = {
192
return all[0];
193
},
194
195
+ /**
196
+ * Pass a mocked component module to this method to augment it with
197
+ * useful methods that allow it to be used as a dummy React component.
198
+ * Instead of rendering as usual, the component will become a simple
199
+ * <div> containing any provided children.
200
+ */
201
+ mockComponent: function(module) {
202
+ var ConvenienceConstructor = React.createClass({
203
+ render: function() {
204
+ return ReactDOM.div(null, this.props.children);
205
+ }
206
+ });
207
+
208
+ copyProperties(module, ConvenienceConstructor);
209
+ module.mockImplementation(function() {
210
+ return ConvenienceConstructor.apply(null, arguments);
211
+ });
212
+
213
+ return this;
214
+ },
215
+
216
/**
217
* Simulates a top level event being dispatched from a raw event that occured
218
* on and `Element` node.