2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-08 16:04:29 +00:00
|
|
|
import {
|
|
|
|
assertEquals,
|
|
|
|
assertExists,
|
|
|
|
AssertionError,
|
|
|
|
assertThrows,
|
|
|
|
} from "./mod.ts";
|
2023-07-13 07:04:30 +00:00
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
Deno.test("assertExists() matches values that are not null or undefined", () => {
|
2023-07-13 07:04:30 +00:00
|
|
|
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);
|
2023-12-08 16:04:29 +00:00
|
|
|
});
|
2023-07-13 07:04:30 +00:00
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
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.',
|
|
|
|
);
|
2023-07-13 07:04:30 +00:00
|
|
|
});
|
2024-05-07 00:08:16 +00:00
|
|
|
|
|
|
|
Deno.test("assertExists() throws with custom message", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => assertExists(undefined, "CUSTOM MESSAGE"),
|
|
|
|
AssertionError,
|
|
|
|
'Expected actual: "undefined" to not be null or undefined: CUSTOM MESSAGE',
|
|
|
|
);
|
|
|
|
});
|