Skip to content

Commit

Permalink
Add a reducer test
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Aug 6, 2015
1 parent f672938 commit 6d44fd0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
24 changes: 0 additions & 24 deletions foo.js

This file was deleted.

43 changes: 43 additions & 0 deletions test/reducer-test.js
Original file line number Diff line number Diff line change
@@ -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()
},
}
}

0 comments on commit 6d44fd0

Please sign in to comment.