@cgnal/redux/test-helpers

Utilities for tests.

Source:

Methods

(static) asHttpFailure(message, extrasopt) → {Object}

Source:
Since:
  • 0.0.18

Test helper to build a HTTP failure result. The function will return an object with a single "error" property containing an Error with the given message and augmented with the optional "extras" properties.

Example
const extras = { status: 401 };

asHttpFailure("some error message", extras) // =>
// {
//     error: Error {
//         // ...
//         message: "some error message",
//         status: 401
//     }
// }
Parameters:
Name Type Attributes Default Description
message String
extras Object <optional>
{}
Returns:
Type
Object

(static) asHttpSuccess(body, extrasopt) → {Object}

Source:
Since:
  • 0.0.18

Test helper to build a HTTP success result. The function will return an object with a single "success" property containing the received body property and augmented with the optional "extras" properties.

Example
const extras = {
    headers: { "Content-Type": "application/json" },
    status: 200
};
const body = [1, 2, 3];

asHttpSuccess(body, extras) // =>
// {
//     success: {
//         "Content-Type": "application/json"
//         "body": [1, 2, 3],
//         "status": 200
//     }
// }
Parameters:
Name Type Attributes Default Description
body Any
extras Object <optional>
{}
Returns:
Type
Object

(static) asResponse(body, extrasopt) → {Object}

Source:
Since:
  • 0.0.18

Test helper to quickly build a fake response object.

Example
const extras = {
    headers: { "Content-Type": "application/json" },
    status: 200
};
const body = [1, 2, 3];

asResponse(body, extras) // =>
// {
//     "Content-Type": "application/json"
//     "body": [1, 2, 3],
//     "status": 200
// }
Parameters:
Name Type Attributes Default Description
body Any
extras Object <optional>
{}
Returns:
Type
Object

(static) asResultKO(value) → {Object}

Source:
Since:
  • 0.0.18

Test helper to build a failure result. Any value passed to the function will be put in the "error" property of an object.

Example
asResultKO({ status: 500 }) // => { error: { status: 500 } }
Parameters:
Name Type Description
value Any
Returns:
Type
Object

(static) asResultOK(value) → {Object}

Source:
Since:
  • 0.0.18

Test helper to build a success result. Any value passed to the function will be put in the "success" property of an object.

Example
asResultOK([1, 2, 3]) // => { success: [1, 2, 3] }
Parameters:
Name Type Description
value Any
Returns:
Type
Object