mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 23:24:37 +00:00
Support more fetch init body types (#1449)
This commit is contained in:
parent
5b9c488921
commit
8d452d74fa
4 changed files with 91 additions and 3 deletions
|
@ -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¶m2=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:
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue