Skip to content

Commit

Permalink
fixup! add namespaced tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Jul 1, 2016
1 parent 8e01352 commit e31ff7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ function dispatcher (handlers) {
if (_reducers && _reducers[actionName]) {
if (ns) {
const reducedState = _reducers[actionName](data, _state[ns])
if (!newState[ns]) newState[ns] = {}
mutate(newState[ns], xtend(_state[ns], reducedState))
} else {
mutate(newState, reducers[actionName](data, _state))
Expand Down
30 changes: 27 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ tape('api: send(name, data?)', (t) => {

tape('handlers: reducers', (t) => {
t.test('should be able to be called', (t) => {
t.plan(5)
t.plan(6)
const store = barracks()
store.model({
namespace: 'meow',
state: { beep: 'boop' },
reducers: {
woof: (action, state) => t.pass('meow.woof called')
}
})

store.model({
state: {
foo: 'bar',
Expand All @@ -192,18 +200,33 @@ tape('handlers: reducers', (t) => {
const send = createSend('tester', true)
send('foo', { foo: 'baz' })
send('sup', 'nope')
send('meow:woof')
process.nextTick(function () {
const state = store.state()
const expected = { foo: 'baz', beep: 'nope' }
const expected = {
foo: 'baz',
beep: 'nope',
meow: { beep: 'boop' }
}
t.deepEqual(state, expected, 'state was updated')
})
})
})

tape('handlers: effects', (t) => {
t.test('should be able to be called', (t) => {
t.plan(4)
t.plan(5)
const store = barracks()

store.model({
namespace: 'meow',
effects: {
woof: (action, state, send, done) => {
t.pass('woof called')
}
}
})

store.model({
state: { bin: 'baz', beep: 'boop' },
reducers: {
Expand All @@ -225,6 +248,7 @@ tape('handlers: effects', (t) => {
const createSend = store.start()
const send = createSend('tester', true)
send('foo', { beep: 'woof' })
send('meow:woof')

process.nextTick(function () {
process.nextTick(function () {
Expand Down

0 comments on commit e31ff7b

Please sign in to comment.