Skip to content

Commit 067eff9

Browse files
committed
Complete tests for compose + composeStores
1 parent aba5fd0 commit 067eff9

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

test/compose.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
// import expect from 'expect';
2-
// import { compose } from '../src';
1+
import expect from 'expect';
2+
import { compose } from '../src';
33

44
describe('Utils', () => {
55
describe('compose', () => {
6+
it('should return combined middleware that executes from left to right', () => {
7+
const a = next => action => next(action + 'a');
8+
const b = next => action => next(action + 'b');
9+
const c = next => action => next(action + 'c');
10+
const dispatch = action => action;
611

7-
it('should return combined middleware that executes from left to right');
12+
expect(compose(a, b, c, dispatch)('')).toBe('abc');
13+
expect(compose(b, c, a, dispatch)('')).toBe('bca');
14+
expect(compose(c, a, b, dispatch)('')).toBe('cab');
15+
});
816
});
917
});

test/composeStores.spec.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
// import expect from 'expect';
2-
// import { composeStores } from '../src';
1+
import expect from 'expect';
2+
import { composeStores } from '../src';
33

44
describe('Utils', () => {
55
describe('composeStores', () => {
6+
it('should return a store that maps state keys to reducer functions', () =>{
7+
const store = composeStores({
8+
counter: (state = 0, action) =>
9+
action.type === 'increment' ? state + 1 : state,
10+
stack: (state = [], action) =>
11+
action.type === 'push' ? [...state, action.value] : state
12+
});
613

7-
it('should call map stores');
14+
const s1 = store({}, { type: 'increment' });
15+
expect(s1).toEqual({ counter: 1, stack: [] });
16+
const s2 = store(s1, { type: 'push', value: 'a' });
17+
expect(s2).toEqual({ counter: 1, stack: ['a'] });
18+
});
819
});
920
});

0 commit comments

Comments
 (0)