utils

Various utility functions used throughout Mocha's codebase.

Source:

Members

(static) inherits

Source:

Inherit the prototype methods from one constructor into another.

(inner) path

Source:

Module dependencies.

Methods

(static) clamp(value, range) → {number}

Source:

Clamps a numeric value to an inclusive range.

Parameters:
NameTypeDescription
valuenumber

Value to be clamped.

rangeArray:.<number:>

Two element array specifying [min, max] range.

Returns:

clamped value

Type
number

(static) clean(str) → {string}

Source:

Strip the function definition from str, and re-indent for pre whitespace.

Parameters:
NameTypeDescription
strstring
Returns:
Type
string

(static) createMap(…objopt) → {Object}

Source:
See:

A "map" is an object with no prototype, for our purposes. In some cases
this would be more appropriate than a Map, especially if your environment
doesn't support it. Recommended for use in Mocha's public APIs.

Parameters:
NameTypeAttributesDescription
obj*<optional>
<repeatable>

Arguments to Object.assign().

Returns:

An object with no prototype, having ...obj properties

Type
Object

(static) defineConstants(…objopt) → {Object}

Source:
See:

This differs from createMap only in that
the argument must be non-empty, because the result is frozen.

Parameters:
NameTypeAttributesDescription
obj*<optional>
<repeatable>

Arguments to Object.assign().

Throws:

if argument is not a non-empty object.

Type
TypeError
Returns:

A frozen object with no prototype, having ...obj properties

Type
Object

(static) getMochaID(objopt) → {string|void}

Source:

Retrieves a Mocha ID from an object, if present.

Parameters:
NameTypeAttributesDescription
obj*<optional>

Object

Returns:
Type
string | void

(static) isPromise(value) → {boolean}

Source:

Crude, but effective.

Parameters:
NameTypeDescription
value*
Returns:

Whether or not value is a Promise

Type
boolean

(static) noop()

Source:

It's a noop.

(static) stackTraceFilter() → {function}

This Filter based on mocha-clean module.(see: github.com/rstacruz/mocha-clean)

Source:

When invoking this function you get a filter function that get the Error.stack as an input,
and return a prettify output.
(i.e: strip Mocha and internal node functions from stack trace).

Returns:
Type
function

(static) uniqueID() → {string}

Source:

Creates a new unique identifier
Does not create cryptographically safe ids.
Trivial copy of nanoid/non-secure

Returns:

Unique identifier

Type
string