-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReactDomTest.js
54 lines (46 loc) · 1.4 KB
/
ReactDomTest.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
50
51
52
53
54
'use strict';
var jsdom = require('jsdom').jsdom;
exports.reset = function(done) {
var doc = jsdom('<html><body></body></html>');
global.window = doc.parentWindow;
global.document = window.document;
global.navigator = window.navigator;
global.$ = undefined;
if (done) {
jsdom.jQueryify(doc.parentWindow, "../../../node_modules/jquery/dist/jquery.js", function () {
done();
});
}
}
exports.reset();
var React = require('react/addons');
var ReactTestUtils = React.addons.TestUtils;
exports.render = function(component) {
var div = document.createElement('div');
React.renderComponent(component, div);
global.$ = function(selector) {
return window.$(div).find(selector);
}
return div;
}
exports.click = function(selector) {
ReactTestUtils.Simulate.click($(selector).get(0));
}
exports.input = function(selector, value) {
var target = $(selector).get(0);
ReactTestUtils.Simulate.change(target, { target: { value: value }});
}
exports.mock = function(subject, componentNameToMock) {
if (typeof subject.__set__ != 'function') {
throw new Error('ReactTest.mock subjects must use rewire');
}
var mock = React.createClass({
render: function() {
return React.DOM.div({id: componentNameToMock}, JSON.stringify(this.props));
}
});
subject.__set__(componentNameToMock, mock);
}
exports.mock.props = function(element) {
return JSON.parse(element.text());
}