Implement Body.formData for fetch (#1393)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-12-21 17:09:53 -05:00 committed by Ryan Dahl
parent 317fddbbf8
commit cbee2895b3
4 changed files with 191 additions and 1 deletions

View file

@ -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:
//