-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
79 lines (70 loc) · 2.02 KB
/
test.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var testReducer = require('./index');
var expect = require('chai').expect;
var goodSample = function(state, action) {
if (action.type === 'INCREMENT') {
return { counter: state.counter + 1 };
} else if (action.type === 'DECREMENT') {
return { counter: state.counter - 1 };
} else {
return { counter: 0 };
}
};
var badSample = function(state, action) {
if (action.type === 'GET_VALUE') {
return 'someOtherValue';
}
};
describe('#testReducer', function() {
var assertReducer;
beforeEach(function() {
assertReducer = testReducer(goodSample);
});
it('can perform deep equality comparisons', function() {
expect(function() {
assertReducer({
from: { counter: 0 },
to: { counter: 1 },
action: { type: 'INCREMENT' },
});
assertReducer({
from: { counter: 1 },
to: { counter: 0 },
action: { type: 'DECREMENT' },
});
}).to.not.throw(Error);
});
it('throws errors for bad reducers', function() {
badAssertReducer = testReducer(badSample);
expect(function() {
badAssertReducer({
from: '',
to: 'someValue',
action: { type: 'GET_VALUE' },
});
}).to.throw(Error);
});
it('throws an error if `from` is not specified', function() {
expect(function() {
assertReducer({
to: { counter: 1 },
action: { type: 'INCREMENT' },
});
}).to.throw('The `from` option was not specified in the reducer assertion call.');
});
it('throws an error if `to` is not specified', function() {
expect(function() {
assertReducer({
from: { counter: 0 },
action: { type: 'INCREMENT' },
});
}).to.throw('The `to` option was not specified in the reducer assertion call.');
});
it('throws an error if `action` is not specified', function() {
expect(function() {
assertReducer({
from: { counter: 0 },
to: { counter: 1 },
});
}).to.throw('The `action` option was not specified in the reducer assertion call.');
});
});