forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.js
32 lines (26 loc) · 916 Bytes
/
test_utils.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
/* Utils for tests. */
import React from "react";
import sinon from "sinon";
import { renderIntoDocument } from "react-addons-test-utils";
import { findDOMNode, render } from "react-dom";
import Form from "../src";
export function createComponent(Component, props) {
const comp = renderIntoDocument(<Component {...props} />);
const node = findDOMNode(comp);
return { comp, node };
}
export function createFormComponent(props) {
return createComponent(Form, { ...props, safeRenderCompletion: true });
}
export function createSandbox() {
const sandbox = sinon.sandbox.create();
// Ensure we catch any React warning and mark them as test failures.
sandbox.stub(console, "error", error => {
throw new Error(error);
});
return sandbox;
}
export function setProps(comp, newProps) {
const node = findDOMNode(comp);
render(React.createElement(comp.constructor, newProps), node.parentNode);
}