-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (26 loc) · 880 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Assertion module for redux reducers.
*/
var assert = require('core-assert');
module.exports = function testReducer(reducer) {
return function assertReducer(options) {
// Extract variables
var from = options.from;
var to = options.to;
var action = options.action;
// Perform invariant checks
if (typeof from === 'undefined') {
assert(false, 'The `from` option was not specified in the reducer assertion call.');
}
if (typeof to === 'undefined') {
assert(false, 'The `to` option was not specified in the reducer assertion call.');
}
if (typeof action === 'undefined') {
assert(false, 'The `action` option was not specified in the reducer assertion call.');
}
// Get the next state
var result = reducer(from, action);
// Assert strict equality
assert.deepStrictEqual(result, to);
};
};