summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Seidel <ivanseidel@gmail.com>2016-06-23 15:19:57 -0300
committerHubert Argasinski <argasinski.hubert@gmail.com>2016-06-29 18:38:52 -0400
commit016fc4b873744a3da3429361036cbc3406ee8b86 (patch)
treef20dcb1fd144b80af0bffaf630af19d1a683a049
parent674697629d1c3dded7fae2b88f54c2f481b4f221 (diff)
downloadasync-016fc4b873744a3da3429361036cbc3406ee8b86.tar.gz
Consider non-explicit parameters in validation
-rw-r--r--lib/autoInject.js7
-rw-r--r--mocha_test/autoInject.js14
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/autoInject.js b/lib/autoInject.js
index 89e8c5e..4b4f6e7 100644
--- a/lib/autoInject.js
+++ b/lib/autoInject.js
@@ -13,7 +13,7 @@ var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function parseParams(func) {
func = func.toString().replace(STRIP_COMMENTS, '');
func = func.match(FN_ARGS)[2].replace(' ', '');
- func = func.split(FN_ARG_SPLIT);
+ func = func ? func.split(FN_ARG_SPLIT) : [];
func = func.map(function (arg){
return trim(arg.replace(FN_ARG, ''));
});
@@ -123,6 +123,11 @@ export default function autoInject(tasks, callback) {
newTasks[key] = taskFn;
} else {
params = parseParams(taskFn);
+ if (taskFn.length === 0 && params.length === 0) {
+ throw new Error("autoInject task functions require explicit parameters.");
+ }
+ console.log(taskFn.length, params)
+
params.pop();
newTasks[key] = params.concat(newTask);
diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js
index e658167..9c2d1fb 100644
--- a/mocha_test/autoInject.js
+++ b/mocha_test/autoInject.js
@@ -85,6 +85,20 @@ describe('autoInject', function () {
}, done);
});
+ it('should throw error for function without explicit parameters', function (done) {
+ try {
+ async.autoInject({
+ a: function (){}
+ });
+ } catch (e) {
+ // It's ok. It detected a void function
+ return done();
+ }
+
+ // If didn't catch error, then it's a failed test
+ done(true)
+ });
+
var arrowSupport = true;
try {
new Function('x => x');