std/streams/limited_transform_stream_test.ts
Yusuke Tanaka 9c3c53e65b
docs(streams): improve docs for stabilization (#4852)
This commit improves docs of the streams module.

Towards #3764

---------

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2024-05-27 18:27:40 -07:00

36 lines
840 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertRejects } from "@std/assert";
import { LimitedTransformStream } from "./limited_transform_stream.ts";
Deno.test("LimitedTransformStream", async function () {
const r = ReadableStream.from([
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
]).pipeThrough(new LimitedTransformStream(3));
const chunks = await Array.fromAsync(r);
assertEquals(chunks, [
"foo",
"foo",
"foo",
]);
});
Deno.test("LimitedTransformStream handles error", async function () {
const r = ReadableStream.from([
"foo",
"foo",
"foo",
"foo",
"foo",
"foo",
]).pipeThrough(new LimitedTransformStream(3, { error: true }));
await assertRejects(async () => await Array.fromAsync(r), RangeError);
});