assert

This module is used for writing unit tests for your applications, you can access it with require('assert'). This is port of NodeJS NodeJS.assert module - see detailed documentation there

Members

assert inner

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

Methods

fail(actual, expected, message, operator, stackStartFunction) inner

Throws an exception that displays the values for actual and expected separated by the provided operator.
Arguments:
  1. actual
  2. expected
  3. message
  4. operator
  5. stackStartFunction

ok(value, message) inner

Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
Arguments:
  1. value
  2. message

equal(actual, expected, messageopt) static

Tests shallow, coercive equality with the equal comparison operator ( == ).
Arguments:
  1. actual
  2. expected
  3. [message] (String)

notEqual(actual, expected, messageopt) static

Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
Arguments:
  1. actual
  2. expected
  3. [message]

deepEqual(actual, expected, messageopt) static

Tests for deep equality.
Arguments:
  1. actual
  2. expected
  3. [message]

notDeepEqual(actual, expected, messageopt) static

Tests for any deep inequality.
Arguments:
  1. actual
  2. expected
  3. [message]

strictEqual(actual, expected, messageopt) static

Tests strict equality, as determined by the strict equality operator ( === )
Arguments:
  1. actual
  2. expected
  3. [message]

notStrictEqual(actual, expected, messageopt) static

Tests strict non-equality, as determined by the strict not equal operator ( !== )
Arguments:
  1. actual
  2. expected
  3. [message]

throws(block, erroropt, messageopt) static

Expects block to throw an error. error can be constructor, RegExp or validation function.

Validate instanceof using constructor:

 assert.throws(function() {
    throw new Error("Wrong value");
 }, Error);

Validate error message using RegExp:

 assert.throws(function() {
    throw new Error("Wrong value");
 }, /error/);

Custom error validation:

 assert.throws(
 function() {
    throw new Error("Wrong value");
  },
 function(err) {
    if ( (err instanceof Error) && /value/.test(err) ) {
      return true;
    }
  },
 "unexpected error"
 );
Arguments:
  1. block
  2. [error]
  3. [message]

doesNotThrow(block, messageopt) static

Expects block not to throw an error, see assert.throws for details.
Arguments:
  1. block
  2. [message]

ifError(err) static

Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.
Arguments:
  1. err