Skip to main content

@std/assert@1.0.19
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
License
MIT
Downloads89,134/wk
Published3 months ago (1.0.19)

Common assertion functions, especially useful for testing

// Copyright 2018-2026 the Deno authors. MIT license. import { assert, assertEquals, AssertionError, assertStringIncludes, assertThrows, } from "./mod.ts"; Deno.test("assertStringIncludes()", () => { assertStringIncludes("Denosaurus", "saur"); assertStringIncludes("Denosaurus", "Deno"); assertStringIncludes("Denosaurus", "rus"); let didThrow; try { assertStringIncludes("Denosaurus", "Raptor"); didThrow = false; } catch (e) { assert(e instanceof AssertionError); didThrow = true; } assertEquals(didThrow, true); }); Deno.test("assertStringIncludes() throws", () => { assertThrows( () => assertStringIncludes("Denosaurus from Jurassic", "Raptor"), AssertionError, `Expected actual: "Denosaurus from Jurassic" to contain: "Raptor".`, ); }); Deno.test("assertStringIncludes() with custom message", () => { assertThrows( () => assertStringIncludes( "Denosaurus from Jurassic", "Raptor", "CUSTOM MESSAGE", ), AssertionError, `Expected actual: "Denosaurus from Jurassic" to contain: "Raptor": CUSTOM MESSAGE`, ); });