assert-jsnext

1.3.0 • Public • Published

assert

Build Status

This is a fork of the original assert package built to support projects built using dependencies with the jsnext:main field.


This module is used for writing unit tests for your applications, you can access it with require('assert-jsnext').

The API is derived from the commonjs 1.0 unit testing spec and the node.js assert module

fail(actual, expected, message, operator)

Throws an exception that displays the values for actual and expected separated by the provided operator.

value, message), ok(value, [message])

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

equal(actual, expected, [message])

Tests shallow, coercive equality with the equal comparison operator ( == ).

notEqual(actual, expected, [message])

Tests shallow, coercive non-equality with the not equal comparison operator ( != ).

deepEqual(actual, expected, [message])

Tests for deep equality.

notDeepEqual(actual, expected, [message])

Tests for any deep inequality.

strictEqual(actual, expected, [message])

Tests strict equality, as determined by the strict equality operator ( === )

notStrictEqual(actual, expected, [message])

Tests strict non-equality, as determined by the strict not equal operator ( !== )

throws(block, [error], [message])

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

Validate instanceof using constructor:

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

Validate error message using RegExp:

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

Custom error validation:

throws(function() {
    throw new Error("Wrong value");
}, function(err) {
    if ( (err instanceof Error) && /value/.test(err) ) {
        return true;
    }
}, "unexpected error");

doesNotThrow(block, [message])

Expects block not to throw an error, see throws for details.

ifError(value)

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

Readme

Keywords

Package Sidebar

Install

npm i assert-jsnext

Weekly Downloads

7

Version

1.3.0

License

MIT

Last publish

Collaborators

  • eventualbuddha