forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Response.arrayBuffer() doesn't return promise (denoland#7618)
- Loading branch information
1 parent
92edc36
commit 5c2e499
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
import { unitTest, assert, assertEquals } from "./test_util.ts"; | ||
|
||
unitTest(async function responseText() { | ||
const response = new Response("hello world"); | ||
const textPromise = response.text(); | ||
assert(textPromise instanceof Promise); | ||
const text = await textPromise; | ||
assert(typeof text === "string"); | ||
assertEquals(text, "hello world"); | ||
}); | ||
|
||
unitTest(async function responseArrayBuffer() { | ||
const response = new Response(new Uint8Array([1, 2, 3])); | ||
const arrayBufferPromise = response.arrayBuffer(); | ||
assert(arrayBufferPromise instanceof Promise); | ||
const arrayBuffer = await arrayBufferPromise; | ||
assert(arrayBuffer instanceof ArrayBuffer); | ||
assertEquals(new Uint8Array(arrayBuffer), new Uint8Array([1, 2, 3])); | ||
}); | ||
|
||
unitTest(async function responseJson() { | ||
const response = new Response('{"hello": "world"}'); | ||
const jsonPromise = response.json(); | ||
assert(jsonPromise instanceof Promise); | ||
const json = await jsonPromise; | ||
assert(json instanceof Object); | ||
assertEquals(json, { hello: "world" }); | ||
}); | ||
|
||
unitTest(async function responseBlob() { | ||
const response = new Response(new Uint8Array([1, 2, 3])); | ||
const blobPromise = response.blob(); | ||
assert(blobPromise instanceof Promise); | ||
const blob = await blobPromise; | ||
assert(blob instanceof Blob); | ||
assertEquals(blob, new Blob([new Uint8Array([1, 2, 3])])); | ||
}); | ||
|
||
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 formDataPromise = response.formData(); | ||
assert(formDataPromise instanceof Promise); | ||
const formData = await formDataPromise; | ||
assert(formData instanceof FormData); | ||
assertEquals(formData, input); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters