Module: Library/Test-Helpers

Test helpers

This module hosts everything needed for tests. Abstraction over the expection engine, abstraction over the basic functions, this module is the Test toolbelt. Little to no test framework logic should be in unit tests to keep them focused on code documentation.

Source:

Methods

(static) convertIntoComputedProperties(object) → {Object}

Convert an object into another object with computed properties by using the given object properties names as variables declared in this module. If they are not defined, this function will assume that they refer to node modules instead of local ones during the computed property resolution.

Parameters:
Name Type Description
object Object

Input object

Source:
Returns:

Converted object

Type
Object
Example
Given an object { a: "foo", b: "bar" }
this function will return an object { [a]: "foo", [b]: "bar" } with a and b
eventually defined as variables in this module.

(static) createResponseMock() → {Object}

Create an Express-like response mock

Source:
Returns:

Response mock

Type
Object

(static) executeTestsInternal(mode, moduleName, assertions) → {Array}

Returns a function that will perform several tests, each with a concatenated description. Descriptions will be concatenated to form a test statement that will have this structure: "Module - Function(): When XXXXXXXXX, it should YYYYYYYYY

Parameters:
Name Type Description
mode String

Execution mode(null = normal, skip, or only)

moduleName String

Tested module description

assertions Array.<Object>

Assertion array to perform

Source:
Returns:

Assertions execution results

Type
Array

(static) idFn(input) → {Mixed}

Identity function

Parameters:
Name Type Description
input Mixed

Value to be returned

Source:
Returns:

Same as input

Type
Mixed

(static) nullFn() → {Null}

Returns null

Source:
Returns:

Null

Type
Null

(static) nullFnHO() → {function}

Returns a function that returns null

Source:
Returns:

Function that returns null

Type
function

(static) rejectFn(reason) → {Promise.<String>}

Returns a rejected Promise

Parameters:
Name Type Description
reason String

Rejection reason

Source:
Returns:

Promise rejected with given reason

Type
Promise.<String>

(static) requireWithStubs(moduleName, customStubs) → {Mixed}

Require a module with stubbed dependencies

Parameters:
Name Type Description
moduleName String

Module name to proxiquire

customStubs Object

Custom stubs for the proxified module

Source:
Returns:

Proxified module

Type
Mixed

(static) resolveFn(value) → {Promise.<Mixed>}

Returns a resolved Promise

Parameters:
Name Type Description
value Mixed

Resolved value

Source:
Returns:

Promise resolved with given value

Type
Promise.<Mixed>

(static) resolveFnHO(value) → {function}

Returns a function that return a resolved Promise with given value

Parameters:
Name Type Description
value Mixed

Resolved value

Source:
Returns:

Function that returns a resolved Promise with given value

Type
function

(static) throwFn(message) → {Error}

Throws an Error

Parameters:
Name Type Description
message String

Error message

Source:
Returns:

Error thrown

Type
Error

(static) throwFnHO(message) → {function}

Returns a function that throws an Error

Parameters:
Name Type Description
message String

Error message

Source:
Returns:

Function that throws an error

Type
function

(static) unitTest(testFn, testDescription, cb) → {function}

Return a function that will execute a test with a given description

Parameters:
Name Type Description
testFn function

Test engine

testDescription String

Unit test description

cb function

Callback called with test engine object

Source:
Returns:

Unit test handler

Type
function

(inner) prepareForTests(testFileName, customStubs) → {Mixed}

Prepare a module for tests by requiring it with stubs Module name is based on the given test file name that will consume the prepared module.

Parameters:
Name Type Description
testFileName String

Test file name

customStubs Object

Custom stubs for the proxified module

Source:
Returns:

Proxified module

Type
Mixed