diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-12-21 17:09:53 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-21 17:09:53 -0500 |
commit | cbee2895b3643aaccd62b221bf1bb4ac6a1ca9fb (patch) | |
tree | c02fb8a8edcea85f86c12a14a9736f3b35357a85 /js/fetch_test.ts | |
parent | 317fddbbf8615b8cb4dc3c0ea7d81c0c80a8e3ee (diff) |
Implement `Body.formData` for fetch (#1393)
Diffstat (limited to 'js/fetch_test.ts')
-rw-r--r-- | js/fetch_test.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/js/fetch_test.ts b/js/fetch_test.ts index cd3e6ebf0..c631f2517 100644 --- a/js/fetch_test.ts +++ b/js/fetch_test.ts @@ -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: // |