diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2020-04-04 03:55:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 14:55:23 -0400 |
commit | 24261744857df3cca8c9e05f07cc85c0346a6751 (patch) | |
tree | 257edb6bc9c88bd879ef27cba77c040e7cd648c3 /cli/js/tests/blob_test.ts | |
parent | cb0acfe305a0f2f13773f41a038d8a919c3730ae (diff) |
feat: Expose ReadableStream and make Blob more standardized (#4581)
Co-authored-by: crowlkats <crowlkats@gmail.com>
Diffstat (limited to 'cli/js/tests/blob_test.ts')
-rw-r--r-- | cli/js/tests/blob_test.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/cli/js/tests/blob_test.ts b/cli/js/tests/blob_test.ts index b60877dd0..af84c37a3 100644 --- a/cli/js/tests/blob_test.ts +++ b/cli/js/tests/blob_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { unitTest, assert, assertEquals } from "./test_util.ts"; +import { concat } from "../../../std/bytes/mod.ts"; +import { decode } from "../../../std/encoding/utf8.ts"; unitTest(function blobString(): void { const b1 = new Blob(["Hello World"]); @@ -67,4 +69,24 @@ unitTest(function nativeEndLine(): void { assertEquals(blob.size, Deno.build.os === "win" ? 12 : 11); }); -// TODO(qti3e) Test the stored data in a Blob after implementing FileReader API. +unitTest(async function blobText(): Promise<void> { + const blob = new Blob(["Hello World"]); + assertEquals(await blob.text(), "Hello World"); +}); + +unitTest(async function blobStream(): Promise<void> { + const blob = new Blob(["Hello World"]); + const stream = blob.stream(); + assert(stream instanceof ReadableStream); + const reader = stream.getReader(); + let bytes = new Uint8Array(); + const read = async (): Promise<void> => { + const { done, value } = await reader.read(); + if (!done && value) { + bytes = concat(bytes, value); + return read(); + } + }; + await read(); + assertEquals(decode(bytes), "Hello World"); +}); |