Skip to content
Titanium SDK
Titanium Docs
Version13.4.1

assert

pseudoAndroidiPhoneiPadmacOSsince 8.1.0

Extended by assert.strict

A Node.js-compatible implementation of the core assert module

Titanium provides a number of shims and ports of core Node.js module functionality.

This module is intended to provide a Node-compatible port of the assert core module.

More details on the Node.js API can be found in their assert module documentation

Note: The assert module can also be invoked as a function and is equivalent to calling the assert.ok method:

  const assert = require('assert');
  assert(value, 'message'); // equivalent to assert.ok(value, 'message')

Properties 2

Methods 15

Tests for deep equality between the actual and expected parameters. Consider using assert.deepStrictEqual() instead. assert.deepEqual() can have surprising results.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

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.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

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.

If asyncFn is a function and it throws an error synchronously, assert.doesNotReject() will return a rejected Promise with that error. If the function does not return a promise, assert.doesNotReject() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped.

Using assert.doesNotReject() is actually not useful because there is little benefit in catching a rejection and then rejecting it again. Instead, consider adding a comment next to the specific code path that should not reject and keep error messages as expressive as possible.

If specified, error can be a Class, RegExp or a validation function. See assert.throws() for more details.

Besides the async nature to await the completion behaves identically to assert.doesNotThrow().

Parameters
ParametersTypeDescription
asyncFnFunction | Promise<Object>

function to invoke

error?RegExp | Function

The expected Error type (class or name)

message?String

error message

Asserts that the function fn does not throw an error.

Using assert.doesNotThrow() is actually not useful because there is no benefit in catching an error and then rethrowing it. Instead, consider adding a comment next to the specific code path that should not throw and keep error messages as expressive as possible.

When assert.doesNotThrow() is called, it will immediately call the fn function.

If an error is thrown and it is the same type as that specified by the error parameter, then an AssertionError is thrown. If the error is of a different type, or if the error parameter is undefined, the error is propagated back to the caller.

If specified, error can be a Class, RegExp or a validation function. See assert.throws() for more details.

Parameters
ParametersTypeDescription
fnFunction

function to invoke

error?RegExp | Function

The expected Error type (class or name)

message?String

error message

Tests shallow, coercive equality between the actual and expected parameters using the Abstract Equality Comparison (==). NaN is special handled and treated as being identical in case both sides are NaN.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

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.

Parameters
ParametersTypeDescription
message?String | Error

error message

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.

Parameters
ParametersTypeDescription
valueany

potentially thrown value/object

Tests for any deep inequality. Opposite of assert.deepEqual().

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

Tests for deep strict inequality. Opposite of assert.deepStrictEqual().

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

Tests shallow, coercive inequality with the Abstract Equality Comparison (!=). NaN is special handled and treated as being identical in case both sides are NaN.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

Tests strict inequality between the actual and expected parameters as determined by the SameValue Comparison.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

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

If value is not truthy, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned. If the message parameter is an instance of an Error then it will be thrown instead of the AssertionError. If no arguments are passed in at all message will be set to the string: 'No value argument passed to \assert.ok()`'`.

Parameters
ParametersTypeDescription
valueany

The input that is checked for being truthy.

message?String | Error

error message

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.

If asyncFn is a function and it throws an error synchronously, assert.rejects() will return a rejected Promise with that error. If the function does not return a promise, assert.rejects() will return a rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases the error handler is skipped.

Besides the async nature to await the completion behaves identically to assert.throws().

If specified, error can be a Class, RegExp, a validation function, an object where each property will be tested for, or an instance of error where each property will be tested for including the non-enumerable message and name properties.

If specified, message will be the message provided by the AssertionError if the asyncFn fails to reject.

Parameters
ParametersTypeDescription
asyncFnFunction | Promise<any>

function to invoke

error?RegExp | Function | Object | Error

The expected Error type (class or name)

message?String

error message

Tests strict equality between the actual and expected parameters as determined by the SameValue Comparison.

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

Expects the function fn to throw an error.

If specified, error can be a Class, RegExp, a validation function, a validation object where each property will be tested for strict deep equality, or an instance of error where each property will be tested for strict deep equality including the non-enumerable message and name properties. When using an object, it is also possible to use a regular expression, when validating against a string property. See below for examples.

If specified, message will be appended to the message provided by the AssertionError if the fn call fails to throw or in case the error validation fails.

Parameters
ParametersTypeDescription
fnFunction

function to invoke

error?RegExp | Function

The expected Error type (class or name)

message?String

error message