# assert

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

- Source: https://titaniumsdk.com/docs/sdk/12.7.0/assert
- Titanium SDK version: 12.7.0
- Kind: pseudo
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 8.1.0

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](https://nodejs.org/api/assert.html)

**Note:** The `assert` module can also be invoked as a function and is equivalent to calling the [assert.ok](https://titaniumsdk.com/docs/sdk/assert.md#ok) method:

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

## Properties

### AssertionError

- Type: assert.AssertionError
- Platforms: Android, iPhone, iPad, macOS

extension of `Error`

### strict

- Type: assert.strict
- Platforms: Android, iPhone, iPad, macOS

an alias of `assert` that enforces strict version of comparison methods

## Methods

### deepEqual

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### deepStrictEqual

- Platforms: Android, iPhone, iPad, macOS

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:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### doesNotReject

- Platforms: Android, iPhone, iPad, macOS

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:

- `asyncFn` (Function | Promise<Object>): function to invoke
- `error` (RegExp | Function, optional): The expected `Error` type (class or name)
- `message` (String, optional): error message

### doesNotThrow

- Platforms: Android, iPhone, iPad, macOS

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:

- `fn` (Function): function to invoke
- `error` (RegExp | Function, optional): The expected `Error` type (class or name)
- `message` (String, optional): error message

### equal

- Platforms: Android, iPhone, iPad, macOS

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:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### fail

- Platforms: Android, iPhone, iPad, macOS

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:

- `message` (String | Error, optional): error message Default: `Failed`.

### ifError

- Platforms: Android, iPhone, iPad, macOS

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:

- `value` (any): potentially thrown value/object

### notDeepEqual

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### notDeepStrictEqual

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### notEqual

- Platforms: Android, iPhone, iPad, macOS

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:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### notStrictEqual

- Platforms: Android, iPhone, iPad, macOS

Tests strict inequality between the actual and expected parameters as determined by the [SameValue Comparison](https://tc39.github.io/ecma262/#sec-samevalue).

Parameters:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### ok

- Platforms: Android, iPhone, iPad, macOS

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:

- `value` (any): The input that is checked for being truthy.
- `message` (String | Error, optional): error message

### rejects

- Platforms: Android, iPhone, iPad, macOS

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:

- `asyncFn` (Function | Promise<any>): function to invoke
- `error` (RegExp | Function | Object | Error, optional): The expected `Error` type (class or name)
- `message` (String, optional): error message

### strictEqual

- Platforms: Android, iPhone, iPad, macOS

Tests strict equality between the actual and expected parameters as determined by the [SameValue Comparison](https://tc39.github.io/ecma262/#sec-samevalue).

Parameters:

- `actual` (any): The actual value
- `expected` (any): The expected value
- `message` (String | Error, optional): error message

### throws

- Platforms: Android, iPhone, iPad, macOS

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:

- `fn` (Function): function to invoke
- `error` (RegExp | Function, optional): The expected `Error` type (class or name)
- `message` (String, optional): error message

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

