Created
July 15, 2020 03:01
-
-
Save jkriss/9eeab707767cbae2256c4856d66ed160 to your computer and use it in GitHub Desktop.
deno response test
This file contains hidden or 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
import { | |
assert, | |
assertEquals, | |
} from "https://deno.land/std/testing/asserts.ts"; | |
// this passes | |
Deno.test("should be able to get text and body from a text response", async () => { | |
const res = new Response('hi') | |
assert(res.body) | |
assertEquals(await res.text(), 'hi') | |
}) | |
// body isn't defined | |
Deno.test("should be able to get text and body from a byte array response", async () => { | |
const bytes = new TextEncoder().encode('hi') | |
assert(bytes.buffer instanceof ArrayBuffer) | |
const res = new Response(bytes.buffer) | |
// @ts-ignore | |
console.log("body source is", res._bodySource) | |
assert(res.body, "body should exist") | |
assertEquals(await res.text(), 'hi') | |
}) | |
// the types say you should be able to create a response from a blob, but you can't | |
Deno.test("should be able to get text and body from a blob response", async () => { | |
const res = new Response(new Blob([new TextEncoder().encode('hi')])) | |
assertEquals(await res.text(), 'hi') | |
assert(res.body, "body should exist") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment