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(dictionnary, object) → {Object}

Convert an object into another object with computed properties by using the given object properties names as keys declared in the given dependency dictionnary. If they are not defined, this function will assume that they refer to node modules instead of project-related ones during the computed property resolution. Usage of the dictionnary is optional, but helpful since you can then use aliases for modules names in your stubs declaration, instead of having to resolve all modules path names (since proxyquire need them)

Parameters:
Name Type Description
dictionnary Object

Dictionnary

object Object

Input object

Source:
Returns:

Converted object

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) prepareForTests(dictionnary, defaultStubs, 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
dictionnary Object

Dictionnary

defaultStubs Object

Default stubs (internal dependencies) of the tested module

testFileName String

Test file name

customStubs Object

Custom stubs for the proxified module

Source:
Returns:

Proxified module

Type
Mixed

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

Require a module with stubbed dependencies

Parameters:
Name Type Description
dictionnary Object

Dictionnary

defaultStubs Object

Default stubs (internal dependencies) of the tested module

moduleName String

Module name to proxiquire

customStubs Object

Custom stubs for the proxified module

Source:
Returns:

Proxified module

Type
Mixed

(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