Skip to content

Commit

Permalink
re #8 add ability to set custom timeout for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
A committed Aug 2, 2015
1 parent 766871d commit 9db610c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ mock.post = defineRoute.bind(null, 'POST');
mock.put = defineRoute.bind(null, 'PUT');
mock.del = defineRoute.bind(null, 'DELETE');

/**
* Request timeout
* @type {number|function}
*/
mock.timeout = 0;

/**
* List of registred callbacks
*/
Expand Down Expand Up @@ -44,7 +50,7 @@ function mock(superagent) {
if (current) {
setTimeout(function() {
cb && cb(null, current());
}, 0);
}, value(mock.timeout));
} else {
oldEnd.call(this, cb);
}
Expand Down Expand Up @@ -125,4 +131,12 @@ Route.prototype.match = function(method, url, body) {
};
};


/**
* Exec function and return value, or just return arg
* @param {fn|any} val Value or fn to exec
*/
function value(val) {
return 'function' === typeof val
? val()
: val;
}

0 comments on commit 9db610c

Please sign in to comment.