This release is 21 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




Downloads58,912/wk
•Published2 years ago (0.224.0)
Common assertion functions, especially useful for testing
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. import { CAN_NOT_DISPLAY } from "./_constants.ts"; import { equal } from "./equal.ts"; import { AssertionError } from "./assertion_error.ts"; /** * Make an assertion that `actual` and `expected` are not equal, deeply. * If not then throw. * * Type parameter can be specified to ensure values under comparison have the same type. * * @example * ```ts * import { assertNotEquals } from "@std/assert/assert-not-equals"; * * assertNotEquals(1, 2); // Doesn't throw * assertNotEquals(1, 1); // Throws * ``` */ export function assertNotEquals<T>(actual: T, expected: T, msg?: string) { if (!equal(actual, expected)) { return; } let actualString: string; let expectedString: string; try { actualString = String(actual); } catch { actualString = CAN_NOT_DISPLAY; } try { expectedString = String(expected); } catch { expectedString = CAN_NOT_DISPLAY; } const msgSuffix = msg ? `: ${msg}` : "."; throw new AssertionError( `Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`, ); }