-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.js
59 lines (50 loc) · 1.44 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
import Immutable from 'seamless-immutable';
import createReducer from '../../creators/createReducer';
import onToggle from '.';
const initialState = {
target: false
};
const setUp = {
state: null
};
beforeEach(() => {
setUp.state = Immutable(initialState);
});
describe('onToggle', () => {
it('Toggles target value based on state value', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onToggle()
});
const toggleAction = { type: '@@ACTION/TYPE', target: 'target' };
setUp.state = reducer(setUp.state, toggleAction);
expect(setUp.state).toEqual({
target: true
});
setUp.state = reducer(setUp.state, toggleAction);
expect(setUp.state).toEqual({
target: false
});
});
it('Sets target value based on payload', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onToggle()
});
setUp.state = reducer(setUp.state, { type: '@@ACTION/TYPE', target: 'target', payload: false });
expect(setUp.state).toEqual({
target: false
});
});
it('Sets target value based on payload with custom selector', () => {
const reducer = createReducer(setUp.state, {
'@@ACTION/TYPE': onToggle(action => action.payload.a.b)
});
setUp.state = reducer(setUp.state, {
type: '@@ACTION/TYPE',
target: 'target',
payload: { a: { b: false } }
});
expect(setUp.state).toEqual({
target: false
});
});
});