summaryrefslogtreecommitdiff
path: root/js/fetch_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/fetch_test.ts')
-rw-r--r--js/fetch_test.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/js/fetch_test.ts b/js/fetch_test.ts
index 773b2eebd..582f92839 100644
--- a/js/fetch_test.ts
+++ b/js/fetch_test.ts
@@ -84,6 +84,57 @@ testPerm({ net: true }, async function fetchURLEncodedFormDataSuccess() {
assertEqual(formData.get("field_2").toString(), "<Deno>");
});
+testPerm({ net: true }, async function fetchInitStringBody() {
+ const data = "Hello World";
+ const response = await fetch("http://localhost:4545/echo_server", {
+ method: "POST",
+ body: data
+ });
+ const text = await response.text();
+ assertEqual(text, data);
+ assert(response.headers.get("content-type").startsWith("text/plain"));
+});
+
+testPerm({ net: true }, async function fetchInitTypedArrayBody() {
+ const data = "Hello World";
+ const response = await fetch("http://localhost:4545/echo_server", {
+ method: "POST",
+ body: new TextEncoder().encode(data)
+ });
+ const text = await response.text();
+ assertEqual(text, data);
+});
+
+testPerm({ net: true }, async function fetchInitURLSearchParamsBody() {
+ const data = "param1=value1&param2=value2";
+ const params = new URLSearchParams(data);
+ const response = await fetch("http://localhost:4545/echo_server", {
+ method: "POST",
+ body: params
+ });
+ const text = await response.text();
+ assertEqual(text, data);
+ assert(
+ response.headers
+ .get("content-type")
+ .startsWith("application/x-www-form-urlencoded")
+ );
+});
+
+testPerm({ net: true }, async function fetchInitBlobBody() {
+ const data = "const a = 1";
+ const blob = new Blob([data], {
+ type: "text/javascript"
+ });
+ const response = await fetch("http://localhost:4545/echo_server", {
+ method: "POST",
+ body: blob
+ });
+ const text = await response.text();
+ assertEqual(text, data);
+ assert(response.headers.get("content-type").startsWith("text/javascript"));
+});
+
// TODO(ry) The following tests work but are flaky. There's a race condition
// somewhere. Here is what one of these flaky failures looks like:
//