Skip to content

Instantly share code, notes, and snippets.

@jkriss
Created July 15, 2020 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkriss/9eeab707767cbae2256c4856d66ed160 to your computer and use it in GitHub Desktop.
Save jkriss/9eeab707767cbae2256c4856d66ed160 to your computer and use it in GitHub Desktop.
deno response test
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