Namespace: conditions

conditions

Condition check library. These methods must be run on a Report object.
Source:

Methods

check(evidence, descriptionopt) → {Report}

A generic check of a condition.
Parameters:
Name Type Attributes Description
evidence If false, 0, '', or undefined, the check is assumed to pass. Otherwise it fails, and this argument will be displayed as the reason why.
description string <optional>
The reason why we care about the check.
Source:
Returns:
Type
Report

cmpNum(arg1, operation, arg2, descriptionopt) → {undefined}

Checks if a relation indeed holds between arguments. See also cmpStr
Parameters:
Name Type Attributes Description
arg1 any First argument
operation string One of '<', '<=', '==', '!=', '>=', or '>'
arg2 any Second argument
description string <optional>
Source:
Returns:
Type
undefined

cmpStr(arg1, operation, arg2, descriptionopt) → {undefined}

Checks if a relation indeed holds between arguments, assuming they are strings. See also cmpNum
Parameters:
Name Type Attributes Description
arg1 any First argument
operation string One of '<', '<=', '==', '!=', '>=', or '>'
arg2 any Second argument
description string <optional>
Source:
Returns:
Type
undefined

deepEqual(actual, expected, optionsopt, descriptionopt) → {undefined}

Compares two structures, outputs diff if differences found.
Parameters:
Name Type Attributes Description
actual any First structure
expected any Structure to compare to
options Object <optional>
Properties
Name Type Description
max number how many differences to output (default 5)
description string <optional>
Source:
Returns:
Type
undefined

equal(actual, expected, descriptionopt) → {Report}

Checks if === holds between two values. If not, both will be stringified and displayed as a diff. See deepEqual to check nested data structures ot objects.
Parameters:
Name Type Attributes Description
actual any
expected any
description string <optional>
Source:
Returns:
Type
Report

fail(descriptionopt) → {Report}

Always fails with a "failed deliberately" message.
Parameters:
Name Type Attributes Description
description string <optional>
Source:
Returns:
Type
Report

forEach(description, array, nested) → {undefined}

Checks that a nested contract holds for each element of an array.
Parameters:
Name Type Description
description string
array Array List of items.
nested Contract First argument given to the callback is a Report object, and the second one is the array item in question.
Source:
Returns:
Type
undefined

match(actual, expected, descriptionopt) → {Report}

Checks if a string matches a regular expression.
Parameters:
Name Type Attributes Description
actual string
expected RegExp
description string <optional>
Source:
Returns:
Type
Report

nested(description, contract) → {Report}

Verify a nested contract.
Parameters:
Name Type Description
description string
contract Contract
Source:
Returns:
Type
Report

ordered(description, array, nested) → {undefined}

Checks that a nested contract holds for each pair of adjacent element of an array (i.e. 1&2, 2&3, 3&4, ...).
Parameters:
Name Type Description
description string
array Array List of items.
nested Contract First argument given to the callback is a Report object, and the second and third ones are the array items in question.
Source:
Returns:
Type
undefined

pass(descriptionopt) → {Report}

Always passes.
Parameters:
Name Type Attributes Description
description string <optional>
Source:
Returns:
Type
Report

type(value, type, descriptionopt) → {undefined}

Checks that a value is of the specified type.
Parameters:
Name Type Attributes Description
value any First argument
type string | function | Array One of 'undefined', 'null', 'number', 'integer', 'nan', 'string', 'boolean', 'object', 'array', a class, or an array containing 1 or more of the above. 'number'/'integer' don't include NaN, and 'object' doesn't include arrays. A function implies an object and an instanceof check. Array means any of the specified types (aka sum of types).
description string <optional>
Source:
Returns:
Type
undefined

within(value, min, max) → {Report}

Checks that value is within closed interval [min, max]
Parameters:
Name Type Description
value number | string
min number | string
max number | string
Source:
Returns:
chainable
Type
Report