diff options
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r-- | std/testing/asserts.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index d46b26ded..55c647d04 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -330,6 +330,23 @@ export function assertNotStrictEquals( } /** + * Make an assertion that actual is not null or undefined. If not + * then thrown. + */ +export function assertExists( + actual: unknown, + msg?: string, +): void { + if (actual === undefined || actual === null) { + if (!msg) { + msg = + `actual: "${actual}" expected to match anything but null or undefined`; + } + throw new AssertionError(msg); + } +} + +/** * Make an assertion that actual includes expected. If not * then thrown. */ |