From 6b10839b93744e36ab52b26aacb4292ba0f1d1ea Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 3 Jul 2024 14:31:13 +1000 Subject: [PATCH] test(assert): add "`assert()` throws if expr is falsy" test --- assert/assert_test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 assert/assert_test.ts diff --git a/assert/assert_test.ts b/assert/assert_test.ts new file mode 100644 index 000000000000..203ca1c80dff --- /dev/null +++ b/assert/assert_test.ts @@ -0,0 +1,10 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assert, AssertionError, assertThrows } from "./mod.ts"; + +Deno.test("assert() throws if expr is falsy", () => { + const FALSY_VALUES = [false, 0, "", null, undefined, NaN]; + for (const value of FALSY_VALUES) { + const msg = crypto.randomUUID(); + assertThrows(() => assert(value, msg), AssertionError, msg); + } +});