forked from reduxjs/redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindActionCreators.spec.js
67 lines (58 loc) · 2.09 KB
/
bindActionCreators.spec.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
import expect from 'expect'
import { bindActionCreators, createStore } from '../src'
import { todos } from './helpers/reducers'
import * as actionCreators from './helpers/actionCreators'
describe('bindActionCreators', () => {
let store
beforeEach(() => {
store = createStore(todos)
})
it('wraps the action creators with the dispatch function', () => {
const boundActionCreators = bindActionCreators(actionCreators, store.dispatch)
expect(
Object.keys(boundActionCreators)
).toEqual(
Object.keys(actionCreators)
)
const action = boundActionCreators.addTodo('Hello')
expect(action).toEqual(
actionCreators.addTodo('Hello')
)
expect(store.getState()).toEqual([
{ id: 1, text: 'Hello' }
])
})
it('supports wrapping a single function only', () => {
const actionCreator = actionCreators.addTodo
const boundActionCreator = bindActionCreators(actionCreator, store.dispatch)
const action = boundActionCreator('Hello')
expect(action).toEqual(actionCreator('Hello'))
expect(store.getState()).toEqual([
{ id: 1, text: 'Hello' }
])
})
it('throws for an undefined actionCreator', () => {
expect(() => {
bindActionCreators(undefined, store.dispatch)
}).toThrow(
'bindActionCreators expected an object or a function, instead received undefined. ' +
'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'
)
})
it('throws for a null actionCreator', () => {
expect(() => {
bindActionCreators(null, store.dispatch)
}).toThrow(
'bindActionCreators expected an object or a function, instead received null. ' +
'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'
)
})
it('throws for a primitive actionCreator', () => {
expect(() => {
bindActionCreators('string', store.dispatch)
}).toThrow(
'bindActionCreators expected an object or a function, instead received string. ' +
'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'
)
})
})