summaryrefslogtreecommitdiff
path: root/cli/js/tests/blob_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/tests/blob_test.ts')
-rw-r--r--cli/js/tests/blob_test.ts24
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");
+});