Skip to content
Titanium SDK
Version13.3.1

You are reading 13.3.1. See this page in 13.4.1.

assert.strict

pseudoAndroidiPhoneiPadmacOS

Extends assert

An extension of assert which overrides some of the methods to use their strict counterparts.

Properties 2

Methods 15

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Parameters
ParametersTypeDescription
actualany

The actual value

expectedany

The expected value

message?String | Error

error message

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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

Inherited from assert

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