deno.land / std@0.224.0 / encoding / _util_test.ts

_util_test.ts
View Documentation
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
55
56
57
58
59
60
61
62
// Copyright 2018-2024 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() throws on 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.", ); assertThrows( () => { validateBinaryLike(Object.create(null)); }, TypeError, "The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type object.", );});
std

Version Info

Tagged at
6 months ago