# assert.strict

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

Availability
0.8
0.8
9.2.0
Extends

NOTE

This is an abstract type. Any object of this structure can be used where this type is used.

# Properties

# AssertionError

Availability
8.1.0
8.1.0
9.2.0
AssertionError :assert.AssertionError

extension of Error


# strict

Availability
8.1.0
8.1.0
9.2.0
strict :assert.strict

an alias of assert that enforces strict version of comparison methods

# Methods

# deepEqual

Availability
8.1.0
8.1.0
9.2.0
deepEqual(actual, expected[, message]) void

equivalent to deepStrictEqual

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# deepStrictEqual

Availability
8.1.0
8.1.0
9.2.0
deepStrictEqual(actual, expected[, message]) void

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

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# doesNotReject

Availability
8.1.0
8.1.0
9.2.0
doesNotReject(asyncFn[, error[, message]]) 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.

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

Name Type Description
asyncFn Function | Promise<Object>

function to invoke

error RegExp | Function

The expected Error type (class or name)

message String

error message

Returns

Type
void

# doesNotThrow

Availability
8.1.0
8.1.0
9.2.0
doesNotThrow(fn[, error[, message]]) void

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

Name Type Description
fn Function

function to invoke

error RegExp | Function

The expected Error type (class or name)

message String

error message

Returns

Type
void

# equal

Availability
8.1.0
8.1.0
9.2.0
equal(actual, expected[, message]) void

equivalent to strictEqual

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# fail

Availability
8.1.0
8.1.0
9.2.0
fail([message]) void

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

Name Type Description
message String | Error

error message

Returns

Type
void

# ifError

Availability
8.1.0
8.1.0
9.2.0
ifError(value) void

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

Name Type Description
value any

potentially thrown value/object

Returns

Type
void

# notDeepEqual

Availability
8.1.0
8.1.0
9.2.0
notDeepEqual(actual, expected[, message]) void

equivalent to notDeepStrictEqual

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# notDeepStrictEqual

Availability
8.1.0
8.1.0
9.2.0
notDeepStrictEqual(actual, expected[, message]) void

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

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# notEqual

Availability
8.1.0
8.1.0
9.2.0
notEqual(actual, expected[, message]) void

equivalent to notStrictEqual

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# notStrictEqual

Availability
8.1.0
8.1.0
9.2.0
notStrictEqual(actual, expected[, message]) void

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

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# ok

Availability
8.1.0
8.1.0
9.2.0
ok(value[, message]) void

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

Name Type Description
value any

The input that is checked for being truthy.

message String | Error

error message

Returns

Type
void

# rejects

Availability
8.1.0
8.1.0
9.2.0
rejects(asyncFn[, error[, message]]) 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.

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

Name Type Description
asyncFn Function | Promise<any>

function to invoke

error RegExp | Function | Object | Error

The expected Error type (class or name)

message String

error message

Returns

Type
void

# strictEqual

Availability
8.1.0
8.1.0
9.2.0
strictEqual(actual, expected[, message]) void

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

Parameters

Name Type Description
actual any

The actual value

expected any

The expected value

message String | Error

error message

Returns

Type
void

# throws

Availability
8.1.0
8.1.0
9.2.0
throws(fn[, error[, message]]) void

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

Name Type Description
fn Function

function to invoke

error RegExp | Function

The expected Error type (class or name)

message String

error message

Returns

Type
void