mirror of
https://github.com/denoland/deno.git
synced 2025-07-28 23:53:53 +00:00
Implement Body.formData
for fetch (#1393)
This commit is contained in:
parent
317fddbbf8
commit
cbee2895b3
4 changed files with 191 additions and 1 deletions
|
@ -58,6 +58,30 @@ testPerm({ net: true }, async function fetchEmptyInvalid() {
|
|||
assertEqual(err.name, "InvalidUri");
|
||||
});
|
||||
|
||||
testPerm({ net: true }, async function fetchMultipartFormDataSuccess() {
|
||||
const response = await fetch(
|
||||
"http://localhost:4545/tests/subdir/multipart_form_data.txt"
|
||||
);
|
||||
const formData = await response.formData();
|
||||
assert(formData.has("field_1"));
|
||||
assertEqual(formData.get("field_1").toString(), "value_1 \r\n");
|
||||
assert(formData.has("field_2"));
|
||||
const file = formData.get("field_2") as File;
|
||||
assertEqual(file.name, "file.js");
|
||||
// Currently we cannot read from file...
|
||||
});
|
||||
|
||||
testPerm({ net: true }, async function fetchURLEncodedFormDataSuccess() {
|
||||
const response = await fetch(
|
||||
"http://localhost:4545/tests/subdir/form_urlencoded.txt"
|
||||
);
|
||||
const formData = await response.formData();
|
||||
assert(formData.has("field_1"));
|
||||
assertEqual(formData.get("field_1").toString(), "Hi");
|
||||
assert(formData.has("field_2"));
|
||||
assertEqual(formData.get("field_2").toString(), "<Deno>");
|
||||
});
|
||||
|
||||
// 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