forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_util_test.ts
54 lines (51 loc) · 1.53 KB
/
_util_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../assert/mod.ts";
import { validateBinaryLike } from "./_util.ts";
Deno.test("validateBinaryLike", () => {
assertEquals(validateBinaryLike("hello"), new TextEncoder().encode("hello"));
assertEquals(
validateBinaryLike(new Uint8Array([1, 2, 3])),
new Uint8Array([1, 2, 3]),
);
assertEquals(
validateBinaryLike(new Uint8Array([1, 2, 3]).buffer),
new Uint8Array([1, 2, 3]),
);
});
Deno.test("validateBinaryLike with invalid inputs", () => {
assertThrows(
() => {
validateBinaryLike(1);
},
TypeError,
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type number.",
);
assertThrows(
() => {
validateBinaryLike(undefined);
},
TypeError,
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type undefined.",
);
assertThrows(
() => {
validateBinaryLike(null);
},
TypeError,
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type null.",
);
assertThrows(
() => {
validateBinaryLike({});
},
TypeError,
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type Object.",
);
assertThrows(
() => {
validateBinaryLike(new class MyClass {}());
},
TypeError,
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type MyClass.",
);
});