Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions test/no-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ 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);
assert.throws(function () {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you also want to make the same change you made to the actor.before statement above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the file after changes, I deleted actor.after and modified actor.before. I think actor.after is redundant in this case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not redundant. It's an additional assertion that should never be hit: after hooks should not be executed. If they are it's a bug.

actor.perform('no-functions', 'INVALID ACTION', 'INVALID CALLBACK');
}, function (err) {
return err.message == 'last argument must be a function';
});

assert.throws(function () {
actor.perform('no-functions', 'NO', 'AFTER');
actor.perform('no-functions', function () {}, 'INVALID CALLBACK');
}, function (err) {
return err.message == 'last argument must be a function';
});