summaryrefslogtreecommitdiff
path: root/std/testing/asserts.ts
diff options
context:
space:
mode:
authorYasser A.Idrissi <spookyframework@gmail.com>2020-10-26 16:46:38 +0100
committerGitHub <noreply@github.com>2020-10-26 16:46:38 +0100
commit35caa160bf9b781d20364d77f53fee6e8f9899c3 (patch)
tree888852814fa920c0423332cb675ccf16980238fb /std/testing/asserts.ts
parentae86cbb551f7b88f83d73a447411f753485e49e2 (diff)
feat(std/testing): Add assertExists assertion (#7874)
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r--std/testing/asserts.ts17
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.
*/