Skip to main content

@std/testing@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score52%
Published2 years ago (0.215.0)
Deprecated

(will be removed after 1.0.0) Import from https://deno.land/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.

Classes

c
AssertionError(message: string)

Error thrown when an assertion fails.

Functions

f
assert(
expr: unknown,
msg?
): asserts expr

Make an assertion, error will be thrown if expr does not have truthy value.

f
assertAlmostEquals(
actual: number,
expected: number,
tolerance?,
msg?: string
): void

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.

f
assertArrayIncludes<T>(
actual: ArrayLikeArg<T>,
expected: ArrayLikeArg<T>,
msg?: string
): void

Make an assertion that actual includes the expected values. If not then an error will be thrown.

f
assertEquals<T>(
actual: T,
expected: T,
msg?: string,
options?: { formatter?: (value: unknown) => string; }
): void

Make an assertion that actual and expected are equal, deeply. If not deeply equal, then throw.

f
assertExists<T>(
actual: T,
msg?: string
): asserts actual is NonNullable<T>

Make an assertion that actual is not null or undefined. If not then throw.

f
assertFalse(
expr: unknown,
msg?
): asserts expr is Falsy

Make an assertion, error will be thrown if expr have truthy value.

f
assertGreater<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual is greater than expected. If not then throw.

f
assertGreaterOrEqual<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual is greater than or equal to expected. If not then throw.

f
assertInstanceOf<T extends AnyConstructor>(
actual: unknown,
expectedType: T,
msg?
): asserts actual is GetConstructorType<T>

Make an assertion that obj is an instance of type. If not then throw.

f
assertIsError<E extends Error = Error>(
error: unknown,
ErrorClass?: new (...args: any[]) => E,
msgMatches?: string | RegExp,
msg?: string
): asserts error is E

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.

f
assertLess<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual is less than expected. If not then throw.

f
assertLessOrEqual<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual is less than or equal to expected. If not then throw.

f
assertMatch(
actual: string,
expected: RegExp,
msg?: string
): void

Make an assertion that actual match RegExp expected. If not then throw.

f
assertNotEquals<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual and expected are not equal, deeply. If not then throw.

f
assertNotInstanceOf<A, T>(
actual: A,
unexpectedType: new (...args: any[]) => T,
msg?: string
): asserts actual is Exclude<A, T>

Make an assertion that obj is not an instance of type. If so, then throw.

f
assertNotMatch(
actual: string,
expected: RegExp,
msg?: string
): void

Make an assertion that actual not match RegExp expected. If match then throw.

f
assertNotStrictEquals<T>(
actual: T,
expected: T,
msg?: string
): void

Make an assertion that actual and expected are not strictly equal. If the values are strictly equal then throw.

f
assertObjectMatch(
actual: Record<PropertyKey, any>,
expected: Record<PropertyKey, unknown>,
msg?: string
): void

Make an assertion that actual object is a subset of expected object, deeply. If not, then throw.

f
assertRejects<E extends Error = Error>(
fn: () => PromiseLike<unknown>,
errorClassOrMsg?: (new (...args: any[]) => E) | string,
msgIncludesOrMsg?: string,
msg?: string
): Promise<E | Error | unknown>
2 overloads

Executes a function which returns a promise, expecting it to reject.

f
assertStrictEquals<T>(
actual: unknown,
expected: T,
msg?: string
): asserts actual is T

Make an assertion that actual and expected are strictly equal. If not then throw.

f
assertStringIncludes(
actual: string,
expected: string,
msg?: string
): void

Make an assertion that actual includes expected. If not then throw.

f
assertThrows<E extends Error = Error>(
fn: () => unknown,
errorClassOrMsg?: (new (...args: any[]) => E) | string,
msgIncludesOrMsg?: string,
msg?: string
): E | Error | unknown
2 overloads

Executes a function, expecting it to throw. If it does not, then it throws.

f
equal(
c: unknown,
d: unknown
): boolean

Deep equality comparison used in assertions

f
fail(msg?: string): never

Forcefully throws a failed assertion.

f
unimplemented(msg?: string): never

Use this to stub out methods that will throw when invoked.

f
unreachable(): never

Use this to assert unreachable code.

Type Aliases

T
AnyConstructor = new (...args: any[]) => any

Any constructor

T
ArrayLikeArg<T> = ArrayLike<T> & object

An array-like object (Array, Uint8Array, NodeList, etc.) that is not a string.

T
Falsy = false | 0 | 0 | "" | null | undefined

Assertion condition for assertFalse.

T
GetConstructorType<T extends AnyConstructor> = T extends new (...args: any) => infer C ? C : never

Gets constructor type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.