Skip to content

Commit

Permalink
explicitly throw an error when the last argument is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Oct 6, 2015
1 parent 8dfe60c commit 7b674e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ module.exports = function execPodCallback(subcommand, args, options, cb) {
cmd = 'pod';
}

if (typeof cb !== 'function') {
throw new TypeError(
String(cb) +
' is not a function. Expected a callback function called after `' +
[cmd].concat(subcommand, args).join(' ') +
'` command runs.'
);
}

return execFileSubcommand(cmd, subcommand, args, options, function callback(err, stdout, stderr) {
if (err) {
err.message = err.message.replace('Command failed: ' + err.cmd + '\n', '$&' + stdout + stderr);
Expand Down
14 changes: 13 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const execPodCallback = require('.');
const test = require('tape');

test('execPodCallback()', t => {
t.plan(17);
t.plan(19);

t.equal(execPodCallback.name, 'execPodCallback', 'should have a function name.');

Expand Down Expand Up @@ -96,4 +96,16 @@ test('execPodCallback()', t => {
/TypeError.*1 is not Boolean\. `bundleExec` option must be Boolean \(`false` by default\)\./,
'should throw a type error when `bundleExec` option is not Boolean.'
);

t.throws(
() => execPodCallback('install', ['AFNetworking', '--verbose'], false),
/TypeError.*callback function called after `pod install AFNetworking --verbose` command runs\./,
'should throw a type error when the last argument is falsy value except for `undefined`.'
);

t.throws(
() => execPodCallback('install', [], 1),
/TypeError.*1 is not a function\. Expected a callback function called after `pod install`/,
'should throw a type error when the last argument is truthy value but not a function.'
);
});

0 comments on commit 7b674e2

Please sign in to comment.