1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/cli/tests/unit/streams_internal_test.ts

80 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-05-20 20:18:43 -04:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assertThrows } from "./test_util.ts";
unitTest(function streamReadableHwmError() {
const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new ReadableStream<number>(
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
{ highWaterMark }
);
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:"
);
}
assertThrows(() => {
new ReadableStream<number>(
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
{ highWaterMark: Symbol("hwk") }
);
}, TypeError);
});
unitTest(function streamWriteableHwmError() {
const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new WritableStream(
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
new CountQueuingStrategy({ highWaterMark })
);
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:"
);
}
assertThrows(() => {
new WritableStream(
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") })
);
}, TypeError);
});
unitTest(function streamTransformHwmError() {
const invalidHwm = [NaN, Number("NaN"), {}, -1, "two"];
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new TransformStream(
undefined,
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
{ highWaterMark }
);
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:"
);
}
assertThrows(() => {
new TransformStream(
undefined,
undefined,
// @ts-expect-error
2020-05-20 20:18:43 -04:00
{ highWaterMark: Symbol("hwmk") }
);
}, TypeError);
});