From e31ff7beb572f405d936c49ca2e2c32e1a80a221 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 1 Jul 2016 18:41:10 +0200 Subject: [PATCH] fixup! add namespaced tests --- index.js | 1 - test.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index beede87..21a07e3 100644 --- a/index.js +++ b/index.js @@ -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)) diff --git a/test.js b/test.js index 67ec507..76f092a 100644 --- a/test.js +++ b/test.js @@ -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', @@ -192,9 +200,14 @@ 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') }) }) @@ -202,8 +215,18 @@ tape('handlers: reducers', (t) => { 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: { @@ -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 () {