@plowtech/rescript-fetch 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/package.json +38 -0
- package/rescript.json +35 -0
- package/src/Fetch.res +561 -0
- package/src/Fetch.res.js +420 -0
- package/src/Fetch.resi +337 -0
- package/tests/FetchTest.res +155 -0
- package/tests/FetchTest.res.js +162 -0
- package/tests/utils/Assert.res +20 -0
- package/tests/utils/Assert.res.js +25 -0
- package/tests/utils/ReactTest.res +47 -0
- package/tests/utils/ReactTest.res.js +41 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
open Test
|
|
2
|
+
open Webapi.Dom
|
|
3
|
+
|
|
4
|
+
@send external remove: Dom.element => unit = "remove"
|
|
5
|
+
|
|
6
|
+
let createContainer = () => {
|
|
7
|
+
let containerElement = Webapi.Dom.document->Document.createElement("div")
|
|
8
|
+
let _ = containerElement->Element.setAttribute("id", "test")
|
|
9
|
+
|
|
10
|
+
let _ =
|
|
11
|
+
Webapi.Dom.document
|
|
12
|
+
->Document.asHtmlDocument
|
|
13
|
+
->Option.map(htmlDocument =>
|
|
14
|
+
htmlDocument
|
|
15
|
+
->HtmlDocument.body
|
|
16
|
+
->Option.forEach(body => body->Element.appendChild(~child=containerElement))
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
ReactDOM.Client.createRoot(containerElement)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let cleanupContainer = container => {
|
|
23
|
+
let containerElement = ReactDOM.querySelector("#test")
|
|
24
|
+
switch containerElement {
|
|
25
|
+
| Some(element) => element->remove
|
|
26
|
+
| None => ()
|
|
27
|
+
}
|
|
28
|
+
container->ReactDOM.Client.Root.unmount()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let testWithReact = testWith(~setup=createContainer, ~teardown=cleanupContainer, ...)
|
|
32
|
+
|
|
33
|
+
let testAsyncWithReact = testAsyncWith(~setup=createContainer, ~teardown=cleanupContainer, ...)
|
|
34
|
+
|
|
35
|
+
// @testing-library/react
|
|
36
|
+
@module("@testing-library/react") external act: (unit => Promise.t<unit>) => Promise.t<unit> = "act"
|
|
37
|
+
|
|
38
|
+
@module("@@testing-library/react")
|
|
39
|
+
external waitFor: (unit => Promise.t<'a>) => Promise.t<'a> = "waitFor"
|
|
40
|
+
|
|
41
|
+
type screen
|
|
42
|
+
|
|
43
|
+
@module("@testing-library/react") @val
|
|
44
|
+
external screen: screen = "screen"
|
|
45
|
+
|
|
46
|
+
@send
|
|
47
|
+
external findByText: (screen, string) => Promise.t<Dom.element> = "findByText"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Test = require("rescript-test/src/Test.res.js");
|
|
5
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
6
|
+
var Core__Option = require("@rescript/core/src/Core__Option.res.js");
|
|
7
|
+
var Client = require("react-dom/client");
|
|
8
|
+
var Webapi__Dom__Document = require("rescript-webapi/src/Webapi/Dom/Webapi__Dom__Document.res.js");
|
|
9
|
+
|
|
10
|
+
function createContainer() {
|
|
11
|
+
var containerElement = document.createElement("div");
|
|
12
|
+
containerElement.setAttribute("id", "test");
|
|
13
|
+
Core__Option.map(Webapi__Dom__Document.asHtmlDocument(document), (function (htmlDocument) {
|
|
14
|
+
Core__Option.forEach(Caml_option.nullable_to_opt(htmlDocument.body), (function (body) {
|
|
15
|
+
body.appendChild(containerElement);
|
|
16
|
+
}));
|
|
17
|
+
}));
|
|
18
|
+
return Client.createRoot(containerElement);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function cleanupContainer(container) {
|
|
22
|
+
var containerElement = document.querySelector("#test");
|
|
23
|
+
if (!(containerElement == null)) {
|
|
24
|
+
containerElement.remove();
|
|
25
|
+
}
|
|
26
|
+
container.unmount();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function testWithReact(extra, extra$1) {
|
|
30
|
+
return Test.testWith(createContainer, cleanupContainer, extra, extra$1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function testAsyncWithReact(extra, extra$1, extra$2) {
|
|
34
|
+
return Test.testAsyncWith(createContainer, cleanupContainer, extra, extra$1, extra$2);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.createContainer = createContainer;
|
|
38
|
+
exports.cleanupContainer = cleanupContainer;
|
|
39
|
+
exports.testWithReact = testWithReact;
|
|
40
|
+
exports.testAsyncWithReact = testAsyncWithReact;
|
|
41
|
+
/* Test Not a pure module */
|