1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00
denoland-deno/cli/tests/unit/streams_internal_test.ts

73 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 { assertThrows, unitTest } from "./test_util.ts";
2020-05-20 20:18:43 -04:00
unitTest(function streamReadableHwmError() {
// deno-lint-ignore no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new ReadableStream<number>(undefined, { highWaterMark });
2020-05-20 20:18:43 -04:00
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new ReadableStream<number>(
undefined,
// deno-lint-ignore no-explicit-any
{ highWaterMark: Symbol("hwk") as any },
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});
unitTest(function streamWriteableHwmError() {
// deno-lint-ignore no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new WritableStream(
undefined,
new CountQueuingStrategy({ highWaterMark }),
2020-05-20 20:18:43 -04:00
);
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new WritableStream(
undefined,
// deno-lint-ignore no-explicit-any
new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") as any }),
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});
unitTest(function streamTransformHwmError() {
// deno-lint-ignore no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new TransformStream(undefined, undefined, { highWaterMark });
2020-05-20 20:18:43 -04:00
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new TransformStream(
undefined,
undefined,
// deno-lint-ignore no-explicit-any
{ highWaterMark: Symbol("hwmk") as any },
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});