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 For 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. If they are not defined, this function will assume that they refer to node modules instead of local ones.
Parameters:
| Name | Type | Description |
|---|---|---|
object |
Object | Input object |
- Source:
Returns:
Converted object
- Type
- Object
(static) createResponseMock() → {Object}
Create an Express-like response mock
- Source:
Returns:
Response mock
- Type
- Object
(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.<Mixed>}
Returns a rejected Promise
Parameters:
| Name | Type | Description |
|---|---|---|
reason |
String | Rejection reason |
- Source:
Returns:
Promise rejected with given reason
- Type
- Promise.<Mixed>
(static) resolveFn(value) → {Promise.<Mixed>}
Returns a resolved Promise
Parameters:
| Name | Type | Description |
|---|---|---|
value |
String | Resolved value |
- Source:
Returns:
Promise resoved 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 |
String | Resolved value |
- Source:
Returns:
Function that returns a resolved Promise with given value
- Type
- function
(static) t(parentBlockDescription, blockDescriptionopt, cb) → {function}
Returns a function that will execute several tests with a concatenated description
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
parentBlockDescription |
String | Parent block description |
|
blockDescription |
String |
<optional> |
This test block description |
cb |
function | Callback |
- Source:
Returns:
Test block handler
- Type
- function
(static) throwFn(error) → {Error}
Throws an Error
Parameters:
| Name | Type | Description |
|---|---|---|
error |
String | Error message |
- Source:
Returns:
Error thrown
- Type
- Error
(static) throwFnHO(error) → {function}
Returns a function that throws an Error
Parameters:
| Name | Type | Description |
|---|---|---|
error |
String | Error message |
- Source:
Returns:
Function that throws an error
- Type
- function
(inner) prepareInstance(moduleName, customContext) → {Mixed}
Require a module and create an instance with defaultStubs, eventually overloaded wit custom context
Parameters:
| Name | Type | Description |
|---|---|---|
moduleName |
String | Module name |
customContext |
Object | Custom context for the module factory |
- Source:
Returns:
Required module instance
- Type
- Mixed
(inner) prepareStubs(moduleName, customStubs) → {Mixed}
Require a proxified module with defaultStubs, eventually overloaded with custom stubs
Parameters:
| Name | Type | Description |
|---|---|---|
moduleName |
String | Proxified module name |
customStubs |
Object | Custom stubs for the proxified module |
- Source:
Returns:
Required proxified module
- Type
- Mixed