Skip to content

Commit

Permalink
closes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarkclements committed Nov 9, 2016
1 parent 723677a commit 61f429c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/mu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function createMu (opts) {

function dispatch (message, cb) {
var id = uuid()

cb = cb || noop
assert(message, 'dispatch requires a valid message')
assert(typeof cb === 'function', 'dispatch requries a valid callback handler')
assert(typeof cb === 'function', 'dispatch requires a valid callback handler')
logger.debug('dispatching message: ' + message)

if (!(message.pattern || message.response)) {
Expand All @@ -88,6 +88,8 @@ function createMu (opts) {
}
}

function noop () {}

createMu.log = Object.keys(pino.levels.values).reduce((acc, key) => {
acc['level' + key[0].toUpperCase() + key.slice(1)] = key
return acc
Expand Down
14 changes: 14 additions & 0 deletions test/core/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,17 @@ test('multi-dispatch same cb', function (t) {
mu.dispatch({role: 'test', cmd: 'one', id: 6}, handler)
})

test('optional cb', function (t) {
t.plan(2)

var mu = createMu()

mu.define({role: 'test', cmd: 'one'}, function (args, cb) {
t.pass()
})

t.doesNotThrow(function () {
mu.dispatch({role: 'test', cmd: 'one'})
})
})

0 comments on commit 61f429c

Please sign in to comment.