Skip to main content

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

Common assertion functions, especially useful for testing

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 Score
100%
Published
4 weeks ago (1.0.11)

default

A library of assertion functions. If the assertion is false an AssertionError will be thrown which will result in pretty-printed diff of the failing assertion.

T
AnyConstructor

Any constructor

T
ArrayLikeArg

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

f
assert

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

f
assertAlmostEquals

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

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

f
assertEquals

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

f
assertExists

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

f
assertFalse

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

f
assertGreater

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

f
assertGreaterOrEqual

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

f
assertInstanceOf

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

c
AssertionError

Error thrown when an assertion fails.

f
assertIsError

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

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

f
assertLessOrEqual

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

f
assertMatch

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

f
assertNotEquals

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

f
assertNotInstanceOf

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

f
assertNotMatch

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

f
assertNotStrictEquals

Make an assertion that actual and expected are not strictly equal, using Object.is for equality comparison. If the values are strictly equal then throw.

f
assertObjectMatch

Make an assertion that expected object is a subset of actual object, deeply. If not, then throw a diff of the objects, with mismatching properties highlighted.

f
assertRejects

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

f
assertStrictEquals

Make an assertion that actual and expected are strictly equal, using Object.is for equality comparison. If not, then throw.

f
assertStringIncludes

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

f
assertThrows

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

f
equal

Deep equality comparison used in assertions.

f
fail

Forcefully throws a failed assertion.

T
Falsy

Assertion condition for assertFalse.

T
GetConstructorType

Gets constructor type

f
unimplemented

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

f
unreachable

Use this to assert unreachable code.

f
assertAlmostEquals

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.

T
ArrayLikeArg

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

f
assertArrayIncludes

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

f
assert

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

c
AssertionError

Error thrown when an assertion fails.

f
equal

Deep equality comparison used in assertions.

f
assertEquals

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

f
assertExists

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

f
fail

Forcefully throws a failed assertion.

f
assertFalse

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

T
Falsy

Assertion condition for assertFalse.

f
assertGreater

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

f
assertGreaterOrEqual

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

T
AnyConstructor

Any constructor

f
assertInstanceOf

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

T
GetConstructorType

Gets constructor type

f
assertIsError

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

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

f
assertLessOrEqual

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

f
assertMatch

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

f
assertNotEquals

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

f
assertNotInstanceOf

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

f
assertNotMatch

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

f
assertNotStrictEquals

Make an assertion that actual and expected are not strictly equal, using Object.is for equality comparison. If the values are strictly equal then throw.

f
assertObjectMatch

Make an assertion that expected object is a subset of actual object, deeply. If not, then throw a diff of the objects, with mismatching properties highlighted.

f
assertRejects

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

f
assertStrictEquals

Make an assertion that actual and expected are strictly equal, using Object.is for equality comparison. If not, then throw.

f
assertStringIncludes

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

f
assertThrows

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

f
unimplemented

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

f
unreachable

Use this to assert unreachable code.

f
assertNever

Make an assertion that x is of type never. If not then throw.