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:
Name Type Description
value number

Value to be clamped.

range Array:.<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:
Name Type Description
str string
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:
Name Type Attributes Description
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:
Name Type Attributes Description
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) isPromise(value) → {boolean}

Source:

Crude, but effective.

Parameters:
Name Type Description
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) supportsEsModules(whether) → {Boolean}

Source:

Versions prior to 10 did not support ES Modules, and version 10 has an old incompatible version of ESM.
This function returns whether Node.JS has ES Module supports that is compatible with Mocha's needs,
which is version >=12.11.

Parameters:
Name Type Description
whether partialSupport

the full Node.js ESM support is available (>= 12) or just something that supports the runtime (>= 10)

Returns:

whether the current version of Node.JS supports ES Modules in a way that is compatible with Mocha

Type
Boolean