From 24261744857df3cca8c9e05f07cc85c0346a6751 Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Sat, 4 Apr 2020 03:55:23 +0900 Subject: feat: Expose ReadableStream and make Blob more standardized (#4581) Co-authored-by: crowlkats --- cli/js/tests/blob_test.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'cli/js/tests/blob_test.ts') 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 { + const blob = new Blob(["Hello World"]); + assertEquals(await blob.text(), "Hello World"); +}); + +unitTest(async function blobStream(): Promise { + 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 => { + const { done, value } = await reader.read(); + if (!done && value) { + bytes = concat(bytes, value); + return read(); + } + }; + await read(); + assertEquals(decode(bytes), "Hello World"); +}); -- cgit v1.2.3