1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const Apemanstore = require('../lib/apemanstore.js'),
|
8 | assert = require('assert');
|
9 |
|
10 | describe('apemanstore', () => {
|
11 |
|
12 | before((done) => {
|
13 | done();
|
14 | });
|
15 |
|
16 | after((done) => {
|
17 | done();
|
18 | });
|
19 |
|
20 |
|
21 | it('Apemanstore', (done) => {
|
22 | let store = new Apemanstore((state, action)=> {
|
23 | return action;
|
24 | }, {});
|
25 | assert.ok(store);
|
26 |
|
27 | store.dispatchAction('hoge', {}, {}, false)
|
28 | .then(() =>
|
29 | store.dispatchErrorAction('fue', {}, {})
|
30 | )
|
31 | .catch(err =>
|
32 | done()
|
33 | );
|
34 | });
|
35 |
|
36 | it('Combined store', (done) => {
|
37 | let store = new Apemanstore({
|
38 | foo(state, action){
|
39 | if (action.type === 'THIS_IS_FOO') {
|
40 | return 'foo-' + action.value;
|
41 | }
|
42 | return state || '';
|
43 | },
|
44 | bar: [
|
45 | (state, action) => {
|
46 | if (action.type === 'THIS_IS_BAR') {
|
47 | return ['bar', action.value, state].join('-');
|
48 | }
|
49 | return state || 'i';
|
50 | },
|
51 | (state, action) => {
|
52 | if (action.type === 'THIS_IS_BAR') {
|
53 | return ['bar2', action.value, state].join('-');
|
54 | }
|
55 | return state || 'i';
|
56 | }
|
57 | ]
|
58 | });
|
59 | assert.ok(store);
|
60 | store.dispatch({type: 'THIS_IS_FOO', value: "z"});
|
61 | store.dispatch({type: 'THIS_IS_BAR', value: "z"});
|
62 | let unsubscribe = store.subscribe(() => {
|
63 |
|
64 | });
|
65 | unsubscribe();
|
66 | let state = store.getState();
|
67 | assert.deepEqual(state, {foo: 'foo-z', bar: 'bar2-z-bar-z-i'});
|
68 | assert.equal(store.getState('foo'), 'foo-z');
|
69 | assert.equal(store.getState('bar'), 'bar2-z-bar-z-i');
|
70 | done();
|
71 | });
|
72 | });
|
73 |
|