This release is 18 versions behind 1.0.16 — the latest version of @std/assert. Jump to latest
Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
Works with
•JSR Score100%•This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




Downloads61,719/wk
•Published2 years ago (0.225.3)
Common assertion functions, especially useful for testing
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. import { AssertionError } from "./assertion_error.ts"; /** * Make an assertion that actual is not null or undefined. * If not then throw. * * @example * ```ts * import { assertExists } from "@std/assert/assert-exists"; * * assertExists("something"); // Doesn't throw * assertExists(undefined); // Throws * ``` */ export function assertExists<T>( actual: T, msg?: string, ): asserts actual is NonNullable<T> { if (actual === undefined || actual === null) { const msgSuffix = msg ? `: ${msg}` : "."; msg = `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`; throw new AssertionError(msg); } }