The Standard Library has been moved to JSR. See the blog post for details.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** * @deprecated (will be removed after 1.0.0) Import from `std/assert/mod.ts` instead. * * A library of assertion functions. * If the assertion is false an `AssertionError` will be thrown which will * result in pretty-printed diff of failing assertion. * * This module is browser compatible, but do not rely on good formatting of * values for AssertionError messages in browsers. * * @module */
export { /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert.ts` instead. * * Make an assertion, error will be thrown if `expr` does not have truthy value. */ assert, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_almost_equals.ts` instead. * * Make an assertion that `actual` and `expected` are almost equal numbers through * a given tolerance. It can be used to take into account IEEE-754 double-precision * floating-point representation limitations. * If the values are not almost equal then throw. * * @example * ```ts * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * assertAlmostEquals(0.1, 0.2); * * // Using a custom tolerance value * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17)); * ``` */ assertAlmostEquals, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_array_includes.ts` instead. * * Make an assertion that `actual` includes the `expected` values. * If not then an error will be thrown. * * Type parameter can be specified to ensure values under comparison have the same type. * * @example * ```ts * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * assertArrayIncludes<number>([1, 2], [2]) * ``` */ assertArrayIncludes, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_equals.ts` instead. * * Make an assertion that `actual` and `expected` are equal, deeply. If not * deeply equal, then throw. * * Type parameter can be specified to ensure values under comparison have the same type. * * @example * ```ts * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("example", function (): void { * assertEquals("world", "world"); * assertEquals({ hello: "world" }, { hello: "world" }); * }); * ``` */ assertEquals, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_exists.ts` instead. * * Make an assertion that actual is not null or undefined. * If not then throw. */ assertExists, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_false.ts` instead. * * Make an assertion, error will be thrown if `expr` have truthy value. */ assertFalse, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_instance_of.ts` instead. * * Make an assertion that `obj` is an instance of `type`. * If not then throw. */ assertInstanceOf, /** @deprecated (will be removed after 1.0.0) Import from `std/assert/assertion_error.ts` instead. */ AssertionError, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_is_error.ts` instead. * * Make an assertion that `error` is an `Error`. * If not then an error will be thrown. * An error class and a string that should be included in the * error message can also be asserted. */ assertIsError, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_match.ts` instead. * * Make an assertion that `actual` match RegExp `expected`. If not * then throw. */ assertMatch, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_equals.ts` instead. * * 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 "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * assertNotEquals<number>(1, 2) * ``` */ assertNotEquals, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_instance_of.ts` instead. * * Make an assertion that `obj` is not an instance of `type`. * If so, then throw. */ assertNotInstanceOf, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_match.ts` instead. * * Make an assertion that `actual` object is a subset of `expected` object, deeply. * If not, then throw. */ assertNotMatch, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_strict_equals.ts` instead. * * Make an assertion that `actual` and `expected` are not strictly equal. * If the values are strictly equal then throw. * * ```ts * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * assertNotStrictEquals(1, 1) * ``` */ assertNotStrictEquals, /** * Make an assertion that `actual` object is a subset of `expected` object, deeply. * If not, then throw. */ assertObjectMatch, /** * Executes a function which returns a promise, expecting it to reject. * If it does not, then it throws. An error class and a string that should be * included in the error message can also be asserted. * * @example * ```ts * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("doesThrow", async function () { * await assertRejects(async () => { * throw new TypeError("hello world!"); * }, TypeError); * await assertRejects( * async () => { * throw new TypeError("hello world!"); * }, * TypeError, * "hello", * ); * }); * * // This test will not pass. * Deno.test("fails", async function () { * await assertRejects( * async () => { * console.log("Hello world"); * }, * ); * }); * ``` * * * @example * ```ts * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("doesThrow", async function () { * await assertRejects( * async () => { * throw new TypeError("hello world!"); * }, * ); * await assertRejects( * async () => { * return Promise.reject(new Error()); * }, * ); * }); * * // This test will not pass. * Deno.test("fails", async function () { * await assertRejects( * async () => { * console.log("Hello world"); * }, * ); * }); * ``` */ assertRejects, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_strict_equals.ts` instead. * * Make an assertion that `actual` and `expected` are strictly equal. If * not then throw. * * @example * ```ts * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("isStrictlyEqual", function (): void { * const a = {}; * const b = a; * assertStrictEquals(a, b); * }); * * // This test fails * Deno.test("isNotStrictlyEqual", function (): void { * const a = {}; * const b = {}; * assertStrictEquals(a, b); * }); * ``` */ assertStrictEquals, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_string_includes.ts` instead. * * Make an assertion that actual includes expected. If not * then throw. */ assertStringIncludes, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_throws.ts` instead. * * Executes a function, expecting it to throw. If it does not, then it * throws. An error class and a string that should be included in the * error message can also be asserted. * * @example * ```ts * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("doesThrow", function (): void { * assertThrows((): void => { * throw new TypeError("hello world!"); * }, TypeError); * assertThrows( * (): void => { * throw new TypeError("hello world!"); * }, * TypeError, * "hello", * ); * }); * * // This test will not pass. * Deno.test("fails", function (): void { * assertThrows((): void => { * console.log("Hello world"); * }); * }); * ``` * * @example * ```ts * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * Deno.test("doesThrow", function (): void { * assertThrows((): void => { * throw new TypeError("hello world!"); * }); * }); * * // This test will not pass. * Deno.test("fails", function (): void { * assertThrows((): void => { * console.log("Hello world"); * }); * }); * ``` */ assertThrows, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/equal.ts` instead. * * Deep equality comparison used in assertions * @param c actual value * @param d expected value */ equal, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/fail.ts` instead. * * Forcefully throws a failed assertion */ fail, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/unimplemented.ts` instead. * * Use this to stub out methods that will throw when invoked. */ unimplemented, /** * @deprecated (will be removed after 1.0.0) Import from `std/assert/unreachable.ts` instead. * * Use this to assert unreachable code. */ unreachable,} from "../assert/mod.ts";