mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
tests: re-enable disabled Response.formData test (#11453)
This commit is contained in:
parent
7d69f06db8
commit
55632266e9
3 changed files with 22 additions and 25 deletions
|
@ -275,7 +275,7 @@ unitTest(
|
|||
await response.formData();
|
||||
},
|
||||
TypeError,
|
||||
"Invalid form data",
|
||||
"Body can not be decoded as form data",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -43,18 +43,17 @@ unitTest(async function responseBlob() {
|
|||
assertEquals(await blob.arrayBuffer(), new Uint8Array([1, 2, 3]).buffer);
|
||||
});
|
||||
|
||||
// TODO(lucacasonato): re-enable test once #10002 is fixed.
|
||||
unitTest({ ignore: true }, async function responseFormData() {
|
||||
unitTest(async function responseFormData() {
|
||||
const input = new FormData();
|
||||
input.append("hello", "world");
|
||||
const response = new Response(input, {
|
||||
headers: { "content-type": "application/x-www-form-urlencoded" },
|
||||
});
|
||||
const response = new Response(input);
|
||||
const contentType = response.headers.get("content-type")!;
|
||||
assert(contentType.startsWith("multipart/form-data"));
|
||||
const formDataPromise = response.formData();
|
||||
assert(formDataPromise instanceof Promise);
|
||||
const formData = await formDataPromise;
|
||||
assert(formData instanceof FormData);
|
||||
assertEquals(formData, input);
|
||||
assertEquals([...formData], [...input]);
|
||||
});
|
||||
|
||||
unitTest(function customInspectFunction(): void {
|
||||
|
|
|
@ -286,27 +286,25 @@
|
|||
});
|
||||
case "FormData": {
|
||||
if (mimeType !== null) {
|
||||
if (mimeType !== null) {
|
||||
const essence = mimesniff.essence(mimeType);
|
||||
if (essence === "multipart/form-data") {
|
||||
const boundary = mimeType.parameters.get("boundary");
|
||||
if (boundary === null) {
|
||||
throw new TypeError(
|
||||
"Missing boundary parameter in mime type of multipart formdata.",
|
||||
);
|
||||
}
|
||||
return parseFormData(bytes, boundary);
|
||||
} else if (essence === "application/x-www-form-urlencoded") {
|
||||
const entries = parseUrlEncoded(bytes);
|
||||
return formDataFromEntries(
|
||||
ArrayPrototypeMap(
|
||||
entries,
|
||||
(x) => ({ name: x[0], value: x[1] }),
|
||||
),
|
||||
const essence = mimesniff.essence(mimeType);
|
||||
if (essence === "multipart/form-data") {
|
||||
const boundary = mimeType.parameters.get("boundary");
|
||||
if (boundary === null) {
|
||||
throw new TypeError(
|
||||
"Missing boundary parameter in mime type of multipart formdata.",
|
||||
);
|
||||
}
|
||||
return parseFormData(bytes, boundary);
|
||||
} else if (essence === "application/x-www-form-urlencoded") {
|
||||
const entries = parseUrlEncoded(bytes);
|
||||
return formDataFromEntries(
|
||||
ArrayPrototypeMap(
|
||||
entries,
|
||||
(x) => ({ name: x[0], value: x[1] }),
|
||||
),
|
||||
);
|
||||
}
|
||||
throw new TypeError("Invalid form data");
|
||||
throw new TypeError("Body can not be decoded as form data");
|
||||
}
|
||||
throw new TypeError("Missing content type");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue