-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.test.js
More file actions
26 lines (21 loc) · 814 Bytes
/
index.test.js
File metadata and controls
26 lines (21 loc) · 814 Bytes
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
const createModule = require('./index').default
const counter = createModule('counter', 0, {
increment: (state, action) => state + 1,
decrement: (state, action) => state - 1,
add: (state, action) => state + action.payload.number
});
test('reducer handles the action correclty', () => {
const newState = counter.reducer(1, counter.actions.increment())
expect(newState).toBe(2)
})
test('reducer handles the action correclty from initialState', () => {
const newState = counter.reducer(undefined, counter.actions.increment())
expect(newState).toBe(1)
})
test('payload is included in the action', () => {
const action = counter.actions.add(5)
expect(action.payload).toBe(5)
})
test('createModule returns action types as an object', () => {
expect(counter.types).toHaveProperty('increment')
})