Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan committed Feb 20, 2018
1 parent 8a1da9e commit 525755b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/composeReducerTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, before */

import chai from 'chai';
import {createReducer} from '../lib/index';
import {createStore} from 'redux';

chai.expect();

const expect = chai.expect;

let store;
let reducer;

describe('Test init', () => {
before(() => {
reducer = createReducer({
a: 1
}).toFunction();
store = createStore(reducer, {});
});
describe('Test init', () => {
it('should return a = 1', () => {
expect(store.getState().a).to.be.equal(1);
});
});
});


35 changes: 35 additions & 0 deletions test/createReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,38 @@ describe('Test init', () => {
});
});

describe('Test state mutation', () => {
before(() => {
reducer = createReducer({
a: 1,
b: 2
})
.when('ACTION', (state, action) => {
return {
...state,
a: state.a + action.payload,
}
})
.when(['ACTION3', 'ACTION4'], (state, action) => ({
...state,
a: state.a - 1,
b: state.b + action.payload,
}))
.toFunction();
store = createStore(reducer, {});
});
describe('Test init', () => {
it('should return a = 1', () => {
store.dispatch({type: 'ACTION1', payload: 2});
store.dispatch({type: 'ACTION', payload: 10});
expect(store.getState()).to.deep.equal({a: 11, b: 2});

store.dispatch({type: 'ACTION3', payload: 1});
expect(store.getState()).to.deep.equal({a: 10, b: 3});

store.dispatch({type: 'ACTION4', payload: 1});
expect(store.getState()).to.deep.equal({a: 9, b: 4});
});
});
});

0 comments on commit 525755b

Please sign in to comment.