-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Verify arguments to series/parallel functions (fixes #4)
- Loading branch information
1 parent
b5c3aa0
commit ca32513
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var assert = require('assert'); | ||
|
||
module.exports = function(args){ | ||
|
||
assert(args.length > 0, 'A set of functions to combine is mandatory'); | ||
|
||
args.forEach(function(arg, argIdx){ | ||
assert.equal(typeof arg, 'function', | ||
'Only functions can be combined, got ' + typeof arg + ' for argument ' + argIdx); | ||
}); | ||
|
||
return args; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
|
||
var verifyArguments = require('../lib/verifyArguments'); | ||
|
||
function validArg() { | ||
} | ||
|
||
test('should act as pass-through for a valid set of arguments', function(t){ | ||
var args = [validArg, validArg]; | ||
t.deepEqual(verifyArguments(args), args); | ||
t.end(); | ||
}); | ||
|
||
test('should throw descriptive error message on invalid argument', function(t){ | ||
t.throws(function(){ | ||
verifyArguments([validArg, 'invalid', validArg]); | ||
}, { | ||
name: 'AssertionError', message: 'Only functions can be combined, got string for argument 1' | ||
}, 'should throw AssertionError'); | ||
t.end(); | ||
}); | ||
|
||
test('should throw descriptive error message on when no arguments provided', function(t){ | ||
t.throws(function(){ | ||
verifyArguments([]); | ||
}, { | ||
name: 'AssertionError', message: 'A set of functions to combine is mandatory' | ||
}, 'should throw AssertionError'); | ||
t.end(); | ||
}); |