forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexists_test.ts
42 lines (38 loc) · 1.1 KB
/
exists_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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import {
assertEquals,
assertExists,
AssertionError,
assertThrows,
} from "./mod.ts";
Deno.test("assertExists() matches values that are not null or undefined", () => {
assertExists("Denosaurus");
assertExists(false);
assertExists(0);
assertExists("");
assertExists(-0);
assertExists(0);
assertExists(NaN);
const value = new URLSearchParams({ value: "test" }).get("value");
assertExists(value);
assertEquals(value.length, 4);
});
Deno.test("assertExists() throws when value is null or undefined", () => {
assertThrows(
() => assertExists(undefined),
AssertionError,
'Expected actual: "undefined" to not be null or undefined.',
);
assertThrows(
() => assertExists(null),
AssertionError,
'Expected actual: "null" to not be null or undefined.',
);
});
Deno.test("assertExists() throws with custom message", () => {
assertThrows(
() => assertExists(undefined, "CUSTOM MESSAGE"),
AssertionError,
'Expected actual: "undefined" to not be null or undefined: CUSTOM MESSAGE',
);
});