forked from rescript-lang/rescript-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactTestUtils.bs.js
106 lines (91 loc) · 2.77 KB
/
ReactTestUtils.bs.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
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
101
102
103
104
105
106
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Curry = require("rescript/lib/js/curry.js");
var Caml_option = require("rescript/lib/js/caml_option.js");
var TestUtils = require("react-dom/test-utils");
function act(func) {
var reactFunc = function () {
Curry._1(func, undefined);
};
TestUtils.act(reactFunc);
}
function actAsync(func) {
return TestUtils.act(function () {
return Curry._1(func, undefined);
});
}
function changeWithValue(element, value) {
var $$event = {
target: {
value: value
}
};
TestUtils.Simulate.change(element, $$event);
}
function changeWithChecked(element, value) {
var $$event = {
target: {
checked: value
}
};
TestUtils.Simulate.change(element, $$event);
}
var 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 Caml_option.undefined_to_opt(Array.from(element.querySelectorAll(selector)).find(function (node) {
return node.textContent === content;
}));
}
function findBySelectorAndPartialTextContent(element, selector, content) {
return Caml_option.undefined_to_opt(Array.from(element.querySelectorAll(selector)).find(function (node) {
return node.textContent.includes(content);
}));
}
var DOM = {
findBySelector: findBySelector,
findByAllSelector: findByAllSelector,
findBySelectorAndTextContent: findBySelectorAndTextContent,
findBySelectorAndPartialTextContent: findBySelectorAndPartialTextContent
};
function prepareContainer(container, param) {
var containerElement = document.createElement("div");
var body = document.body;
if (body !== undefined) {
Caml_option.valFromOption(body).appendChild(containerElement);
}
container.contents = Caml_option.some(containerElement);
}
function cleanupContainer(container, param) {
var contents = container.contents;
if (contents !== undefined) {
Caml_option.valFromOption(contents).remove();
}
container.contents = undefined;
}
function getContainer(container) {
var contents = container.contents;
if (contents !== undefined) {
return Caml_option.valFromOption(contents);
}
throw {
RE_EXN_ID: "Not_found",
Error: new Error()
};
}
exports.act = act;
exports.actAsync = actAsync;
exports.Simulate = Simulate;
exports.DOM = DOM;
exports.prepareContainer = prepareContainer;
exports.cleanupContainer = cleanupContainer;
exports.getContainer = getContainer;
/* react-dom/test-utils Not a pure module */