diff --git a/index.js b/index.js index dfaa0fe..2a41cd8 100644 --- a/index.js +++ b/index.js @@ -42,12 +42,13 @@ function perform(action /* , args..., performFn, callback*/) { if (typeof action !== 'string') throw new Error('event must be a string'); var callback = arguments[arguments.length - 1]; var performFn = arguments[arguments.length - 2]; + if (typeof callback !== 'function') { + throw new Error('last argument must be a function'); + } + + // Allow callback to be omitted by using last arg as performFn var slice = -2; if (typeof performFn !== 'function') { - if (typeof callback !== 'function') { - throw new Error('performFn and callback must be a function'); - } - performFn = callback; callback = null; slice = -1; diff --git a/test/no-functions.js b/test/no-functions.js index f319fdd..84eca7d 100644 --- a/test/no-functions.js +++ b/test/no-functions.js @@ -5,13 +5,20 @@ var Understudy = require('../').Understudy; var actor = new Understudy(); actor.before('no-functions', function () { - assert.equal(true, false); + throw new Error('before shouldn\'t be reached'); }); actor.after('no-functions', function () { - assert.equal(true, false); + throw new Error('after shouldn\'t be reached'); }); assert.throws(function () { - actor.perform('no-functions', 'NO', 'AFTER'); -}); + actor.perform('no-functions', 'INVALID ACTION', 'INVALID CALLBACK'); +}, /last argument must be a function/); + +assert.throws(function () { + function action () { + throw new Error('action shouldn\'t be reached'); + } + actor.perform('no-functions', action, 'INVALID CALLBACK'); +}, /last argument must be a function/);