|
1 | 1 | import expect from 'expect';
|
2 | 2 | import { bindActionCreators, createRedux } from '../../src';
|
| 3 | +import * as helpers from '../_helpers'; |
3 | 4 |
|
4 |
| -const fakeState = { foo: 'bar' }; |
5 |
| - |
6 |
| -function fakeStore(state = 0, action) { |
7 |
| - if (action.type) { |
8 |
| - return fakeState; |
9 |
| - } |
10 |
| - return state; |
11 |
| -} |
12 |
| - |
13 |
| -const fakeActionCreators = { |
14 |
| - foo() { |
15 |
| - return { type: 'FOO' }; |
16 |
| - }, |
17 |
| - fooAsync() { |
18 |
| - return dispatch => { |
19 |
| - setImmediate(() => { |
20 |
| - dispatch({ type: 'FOO_ASYNC' }); |
21 |
| - }); |
22 |
| - }; |
23 |
| - } |
24 |
| -}; |
| 5 | +const { todoActions, todoStore } = helpers; |
25 | 6 |
|
26 | 7 | describe('Utils', () => {
|
27 | 8 | describe('bindActionCreators', () => {
|
28 | 9 |
|
29 | 10 | let redux;
|
30 | 11 |
|
31 | 12 | beforeEach(() => {
|
32 |
| - redux = createRedux({ fakeStore }); |
| 13 | + redux = createRedux({ todoStore }); |
33 | 14 | });
|
34 | 15 |
|
35 | 16 | it('should bind given actions to the dispatcher', done => {
|
36 | 17 | let expectedCallCount = 2;
|
37 |
| - // Let us subscribe to monitor the dispatched actions |
| 18 | + // just for monitoring the dispatched actions |
38 | 19 | redux.subscribe(() => {
|
39 | 20 | expectedCallCount--;
|
40 |
| - const state = redux.getState(); |
41 |
| - |
42 |
| - expect(state.fakeStore).toEqual(fakeState); |
43 | 21 | if (expectedCallCount === 0) {
|
| 22 | + const state = redux.getState(); |
| 23 | + expect(state.todoStore).toEqual([ |
| 24 | + { id: 2, text: 'World' }, |
| 25 | + { id: 1, text: 'Hello' } |
| 26 | + ]); |
44 | 27 | done();
|
45 | 28 | }
|
46 | 29 | });
|
47 |
| - const actions = bindActionCreators(fakeActionCreators, redux.dispatch); |
48 |
| - expect(Object.keys(actions)) |
49 |
| - .toEqual(Object.keys(fakeActionCreators)); |
| 30 | + const actions = bindActionCreators(todoActions, redux.dispatch); |
| 31 | + expect(Object.keys(actions)).toEqual(Object.keys(todoActions)); |
50 | 32 |
|
51 |
| - actions.foo(); |
52 |
| - actions.fooAsync(); |
| 33 | + actions.addTodo('Hello'); |
| 34 | + actions.addTodoAsync('World'); |
53 | 35 | });
|
54 | 36 | });
|
55 | 37 | });
|
0 commit comments