diff --git a/foo.js b/foo.js deleted file mode 100644 index 586285e8..00000000 --- a/foo.js +++ /dev/null @@ -1,24 +0,0 @@ -import Alt from './' -import { combine, reduceWith } from './utils/reducers' - -const alt = new Alt() - -const actions = alt.generateActions('fire', 'foo', 'bar') - -const store = alt.createStore({ - state: 21, - - displayName: 'ValueStore', - - reduce: combine( - reduceWith([actions.fire], (state, payload) => { - return state + 1 - }) - ) -}) - -store.listen(state => console.log('CHANGED', state)) -actions.fire() -actions.foo() -actions.bar() -actions.fire() diff --git a/test/reducer-test.js b/test/reducer-test.js new file mode 100644 index 00000000..12787e06 --- /dev/null +++ b/test/reducer-test.js @@ -0,0 +1,43 @@ +import { assert } from 'chai' +import Alt from '../' +import sinon from 'sinon' +import { combine, reduceWith } from '../utils/reducers' + +const alt = new Alt() + +const actions = alt.generateActions('fire', 'foo', 'bar') + +const store = alt.createStore({ + state: 21, + + displayName: 'ValueStore', + + reduce: combine( + reduceWith([actions.fire], (state, payload) => { + return state + 1 + }) + ) +}) + +export default { + 'value stores': { + beforeEach() { + alt.recycle() + }, + + 'reducer utils help ease the pain of switch statements'() { + const spy = sinon.spy() + const unlisten = store.listen(spy) + + actions.fire() + actions.foo() + actions.bar() + actions.fire() + + assert(store.getState() === 23, 'state is correct') + assert.ok(spy.calledTwice, 'spy was only called twice') + + unlisten() + }, + } +}