Package-level declarations

Types

Link copied to clipboard
external class AssertionError : Throwable

Indicates the failure of an assertion. All errors thrown by the node:assert module will be instances of the AssertionError class.

Link copied to clipboard
sealed external interface AssertionErrorOptions
Link copied to clipboard
typealias AssertPredicate = Any
Link copied to clipboard
external class CallTracker

This feature is deprecated and will be removed in a future version. Please consider using alternatives such as the mock helper function.

Link copied to clipboard
sealed external interface CallTrackerCall
Link copied to clipboard
sealed external interface CallTrackerReportInformation

Functions

Link copied to clipboard
external fun assert(value: Any?)
external fun assert(value: Any?, message: String = definedExternally)
external fun assert(value: Any?, message: JsError = definedExternally)

An alias of {@link ok}.

Link copied to clipboard
external fun <T> deepEqual(actual: Any?, expected: T)
external fun <T> deepEqual(actual: Any?, expected: T, message: String = definedExternally)
external fun <T> deepEqual(actual: Any?, expected: T, message: JsError = definedExternally)

Tests for deep equality between the actual and expected parameters. "Deep" equality means that the enumerable "own" properties of child objects are recursively evaluated also by the following rules.

Link copied to clipboard
external fun doesNotMatch(value: String, regExp: RegExp)
external fun doesNotMatch(value: String, regExp: RegExp, message: String = definedExternally)
external fun doesNotMatch(value: String, regExp: RegExp, message: JsError = definedExternally)

Expects the string input not to match the regular expression.

Link copied to clipboard
suspend fun doesNotReject(block: Promise<Any?>): Void
suspend fun doesNotReject(block: Promise<Any?>, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: Promise<Any?>, message: JsError = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: () -> Promise<Any?>, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: () -> Promise<Any?>, message: JsError = undefined.unsafeCast<Nothing>()): Void

Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected.

suspend fun doesNotReject(block: () -> Promise<Any?>): Void
suspend fun doesNotReject(block: Promise<Any?>, error: AssertPredicate): Void
suspend fun doesNotReject(block: () -> Promise<Any?>, error: AssertPredicate): Void
suspend fun doesNotReject(block: Promise<Any?>, error: AssertPredicate, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: Promise<Any?>, error: AssertPredicate, message: JsError = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: () -> Promise<Any?>, error: AssertPredicate, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun doesNotReject(block: () -> Promise<Any?>, error: AssertPredicate, message: JsError = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun doesNotRejectAsync(block: Promise<Any?>): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>): Promise<Void>
external fun doesNotRejectAsync(block: Promise<Any?>, message: String = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: Promise<Any?>, message: JsError = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>, message: String = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>, message: JsError = definedExternally): Promise<Void>

Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected.

external fun doesNotRejectAsync(block: Promise<Any?>, error: AssertPredicate): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>, error: AssertPredicate): Promise<Void>
external fun doesNotRejectAsync(block: Promise<Any?>, error: AssertPredicate, message: String = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: Promise<Any?>, error: AssertPredicate, message: JsError = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>, error: AssertPredicate, message: String = definedExternally): Promise<Void>
external fun doesNotRejectAsync(block: () -> Promise<Any?>, error: AssertPredicate, message: JsError = definedExternally): Promise<Void>
Link copied to clipboard
external fun doesNotThrow(block: () -> Any?)
external fun doesNotThrow(block: () -> Any?, message: String = definedExternally)
external fun doesNotThrow(block: () -> Any?, message: JsError = definedExternally)

Asserts that the function fn does not throw an error.

external fun doesNotThrow(block: () -> Any?, error: AssertPredicate)
external fun doesNotThrow(block: () -> Any?, error: AssertPredicate, message: String = definedExternally)
external fun doesNotThrow(block: () -> Any?, error: AssertPredicate, message: JsError = definedExternally)
Link copied to clipboard
external fun <T> equal(actual: Any?, expected: T)
external fun <T> equal(actual: Any?, expected: T, message: String = definedExternally)
external fun <T> equal(actual: Any?, expected: T, message: JsError = definedExternally)

Tests strict equality between the actual and expected parameters as determined by Object.is().

Link copied to clipboard
external fun fail(): Nothing
external fun fail(message: String = definedExternally): Nothing
external fun fail(message: JsError = definedExternally): Nothing

Throws an AssertionError with the provided error message or a default error message. If the message parameter is an instance of an Error then it will be thrown instead of the AssertionError.

external fun fail(actual: Any?, expected: Any?): Nothing
external fun fail(actual: Any?, expected: Any?, message: String = definedExternally, operator: String = definedExternally, stackStartFn: Function<*> = definedExternally): Nothing
external fun fail(actual: Any?, expected: Any?, message: JsError = definedExternally, operator: String = definedExternally, stackStartFn: Function<*> = definedExternally): Nothing
Link copied to clipboard
external fun ifError(value: Any?)

Throws value if value is not undefined or null. This is useful when testing the error argument in callbacks. The stack trace contains all frames from the error passed to ifError() including the potential new frames for ifError() itself.

Link copied to clipboard
external fun match(value: String, regExp: RegExp)
external fun match(value: String, regExp: RegExp, message: String = definedExternally)
external fun match(value: String, regExp: RegExp, message: JsError = definedExternally)

Expects the string input to match the regular expression.

Link copied to clipboard
external fun notDeepEqual(actual: Any?, expected: Any?)
external fun notDeepEqual(actual: Any?, expected: Any?, message: String = definedExternally)
external fun notDeepEqual(actual: Any?, expected: Any?, message: JsError = definedExternally)

Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.

Link copied to clipboard
external fun notEqual(actual: Any?, expected: Any?)
external fun notEqual(actual: Any?, expected: Any?, message: String = definedExternally)
external fun notEqual(actual: Any?, expected: Any?, message: JsError = definedExternally)

Tests strict inequality between the actual and expected parameters as determined by Object.is().

Link copied to clipboard
external fun ok(value: Any?)
external fun ok(value: Any?, message: String = definedExternally)
external fun ok(value: Any?, message: JsError = definedExternally)

Tests if value is truthy. It is equivalent to assert.equal(!!value, true, message).

Link copied to clipboard
suspend fun rejects(block: Promise<Any?>): Void
suspend fun rejects(block: Promise<Any?>, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: Promise<Any?>, message: JsError = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: () -> Promise<Any?>, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: () -> Promise<Any?>, message: JsError = undefined.unsafeCast<Nothing>()): Void

Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is rejected.

suspend fun rejects(block: () -> Promise<Any?>): Void
suspend fun rejects(block: Promise<Any?>, error: AssertPredicate): Void
suspend fun rejects(block: () -> Promise<Any?>, error: AssertPredicate): Void
suspend fun rejects(block: Promise<Any?>, error: AssertPredicate, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: Promise<Any?>, error: AssertPredicate, message: JsError = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: () -> Promise<Any?>, error: AssertPredicate, message: String = undefined.unsafeCast<Nothing>()): Void
suspend fun rejects(block: () -> Promise<Any?>, error: AssertPredicate, message: JsError = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun rejectsAsync(block: Promise<Any?>): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>): Promise<Void>
external fun rejectsAsync(block: Promise<Any?>, message: String = definedExternally): Promise<Void>
external fun rejectsAsync(block: Promise<Any?>, message: JsError = definedExternally): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>, message: String = definedExternally): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>, message: JsError = definedExternally): Promise<Void>

Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is rejected.

external fun rejectsAsync(block: Promise<Any?>, error: AssertPredicate): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>, error: AssertPredicate): Promise<Void>
external fun rejectsAsync(block: Promise<Any?>, error: AssertPredicate, message: String = definedExternally): Promise<Void>
external fun rejectsAsync(block: Promise<Any?>, error: AssertPredicate, message: JsError = definedExternally): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>, error: AssertPredicate, message: String = definedExternally): Promise<Void>
external fun rejectsAsync(block: () -> Promise<Any?>, error: AssertPredicate, message: JsError = definedExternally): Promise<Void>
Link copied to clipboard
external fun throws(block: () -> Any?)
external fun throws(block: () -> Any?, message: String = definedExternally)
external fun throws(block: () -> Any?, message: JsError = definedExternally)

Expects the function fn to throw an error.

external fun throws(block: () -> Any?, error: AssertPredicate)
external fun throws(block: () -> Any?, error: AssertPredicate, message: String = definedExternally)
external fun throws(block: () -> Any?, error: AssertPredicate, message: JsError = definedExternally)