-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.js
40 lines (33 loc) · 1.26 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
import Immutable from 'seamless-immutable';
import createReducer from '../../creators/createReducer';
import onReadValue from '.';
const initialState = {
aTarget: null,
count: 1
};
const setUp = {
state: null
};
beforeEach(() => {
setUp.state = Immutable(initialState);
});
describe('onReadValue', () => {
it('Reads a value from a payload', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onReadValue()
});
const newState = reducer(setUp.state, { type: '@@ACTION/TYPE', payload: 'An elephant', target: 'aTarget' });
expect(newState.aTarget).toBe('An elephant');
});
it('Reads a custom value from the payload or the state', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/ELEPHUN': onReadValue(action => action.payload.elephantCount),
'@@ACTION/ELECOUNT': onReadValue((action, state) => action.payload.elephantCount + state.count)
});
let newState = reducer(setUp.state, { type: '@@ACTION/ELEPHUN', payload: { elephantCount: 3 }, target: 'aTarget' });
expect(newState.aTarget).toBe(3);
newState = reducer(newState, { type: '@@ACTION/ELECOUNT', payload: { elephantCount: 5 }, target: 'count' });
expect(newState.count).toBe(6);
expect(newState.aTarget).toBe(3);
});
});