-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathReactTestUtils.res.js
More file actions
100 lines (85 loc) · 2.36 KB
/
Copy pathReactTestUtils.res.js
File metadata and controls
100 lines (85 loc) · 2.36 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
import * as TestUtils from "react-dom/test-utils";
function act(func) {
let reactFunc = () => {
func();
};
TestUtils.act(reactFunc);
}
function actAsync(func) {
return TestUtils.act(() => func());
}
function changeWithValue(element, value) {
let event = {
target: {
value: value
}
};
TestUtils.Simulate.change(element, event);
}
function changeWithChecked(element, value) {
let event = {
target: {
checked: value
}
};
TestUtils.Simulate.change(element, event);
}
let Simulate = {
changeWithValue: changeWithValue,
changeWithChecked: changeWithChecked
};
function findBySelector(element, selector) {
return element.querySelector(selector);
}
function findByAllSelector(element, selector) {
return Array.from(element.querySelectorAll(selector));
}
function findBySelectorAndTextContent(element, selector, content) {
return Array.from(element.querySelectorAll(selector)).find(node => node.textContent === content);
}
function findBySelectorAndPartialTextContent(element, selector, content) {
return Array.from(element.querySelectorAll(selector)).find(node => node.textContent.includes(content));
}
let DOM = {
findBySelector: findBySelector,
findByAllSelector: findByAllSelector,
findBySelectorAndTextContent: findBySelectorAndTextContent,
findBySelectorAndPartialTextContent: findBySelectorAndPartialTextContent
};
function prepareContainer(container, param) {
let containerElement = document.createElement("div");
let body = document.body;
if (body !== undefined) {
Primitive_option.valFromOption(body).appendChild(containerElement);
}
container.contents = Primitive_option.some(containerElement);
}
function cleanupContainer(container, param) {
let contents = container.contents;
if (contents !== undefined) {
Primitive_option.valFromOption(contents).remove();
}
container.contents = undefined;
}
function getContainer(container) {
let contents = container.contents;
if (contents !== undefined) {
return Primitive_option.valFromOption(contents);
}
throw {
RE_EXN_ID: "Not_found",
Error: new Error()
};
}
export {
act,
actAsync,
Simulate,
DOM,
prepareContainer,
cleanupContainer,
getContainer,
}
/* react-dom/test-utils Not a pure module */