Module assert

Assertion library covering the CommonJS Unit Testing specification and a few additional convenience methods.

Functions


ArgumentsError (message)

Creates a new ArgumentsError instance

Parameters

String message The exception message

Returns

A newly created ArgumentsError instance

ArgumentsError.prototype.message


ArgumentsError.prototype.stackTrace


AssertionError (options)

Constructs a new AssertionError instance

Parameters

Object options An object containing error details

AssertionError.prototype.actual


AssertionError.prototype.expected


AssertionError.prototype.message


AssertionError.prototype.name


AssertionError.prototype.stackTrace


deepEqual (actual, expected)

Checks if the values passed as arguments are deep equal

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

equal (actual, expected)

Checks if the values passed as arguments are equal.

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

fail (options)

Basic failure method

Parameters

Object|String options An object containing optional "message", "actual" and "expected" properties, or alternatively a message string

Throws

AssertionError

isFalse (val)

Checks if the value passed as argument is boolean false.

Parameters

Object val The value that should be boolean false.

Throws

ArgumentsError, AssertionError

isNaN (val)

Checks if the value passed as argument is NaN.

Parameters

Object val The value that should be NaN.

Throws

ArgumentsError, AssertionError

isNotNaN (val)

Checks if the value passed as argument is not NaN.

Parameters

Object val The value that should be not NaN.

Throws

ArgumentsError, AssertionError

isNotNull (val)

Checks if the value passed as argument is not null.

Parameters

Object val The value that should be not null.

Throws

ArgumentsError, AssertionError

isNotUndefined (val)

Checks if the value passed as argument is not undefined.

Parameters

Object val The value that should be not undefined.

Throws

ArgumentsError, AssertionError

isNull (val)

Checks if the value passed as argument is null.

Parameters

Object val The value that should be null.

Throws

ArgumentsError, AssertionError

isTrue (val)

Checks if the value passed as argument is boolean true.

Parameters

Object val The value that should be boolean true.

Throws

ArgumentsError, AssertionError

isUndefined (val)

Checks if the value passed as argument is undefined.

Parameters

Object val The value that should be undefined.

Throws

ArgumentsError, AssertionError

matches (value, expr)

Checks if the regular expression matches the string.

Parameters

String value The string that should contain the regular expression pattern
RegExp expr The regular expression that should match the value

Throws

ArgumentsError, AssertionError

notDeepEqual (actual, expected)

Checks if the values passed as arguments are not deep equal

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

notEqual (actual, expected)

Checks if the values passed as arguments are not equal.

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

notStrictEqual (actual, expected)

Checks if the values passed as arguments are not strictly equal

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

ok (value)

Checks if the value passed as argument is truthy.

Parameters

Object value The value to check for truthiness

Throws

ArgumentsError, AssertionError

strictEqual (actual, expected)

Checks if the values passed as arguments are strictly equal

Parameters

Object actual The actual value
Object expected The expected value

Throws

ArgumentsError, AssertionError

stringContains (value, pattern)

Checks if the value passed as argument contains the pattern specified.

Parameters

String value The string that should contain the pattern
String pattern The string that should be contained

Throws

ArgumentsError, AssertionError

throws (func, expectedError)

Checks if the function passed as argument throws a defined exception.

Parameters

Object func The function to call
Object expectedError Optional object expected to be thrown when executing the function

Throws

ArgumentsError, AssertionError