diff options
author | Augusto Franzoia <ajfranzoia@gmail.com> | 2016-03-08 01:21:24 -0300 |
---|---|---|
committer | Augusto Franzoia <ajfranzoia@gmail.com> | 2016-03-08 02:15:50 -0300 |
commit | ff06a8283458db5624447f99d2c359e1711b8c99 (patch) | |
tree | 3d9bb1d0905ee48a515e8f0f81a5c48808fe2860 | |
parent | 07208a6003b49b4984ff8e205d37738192239319 (diff) | |
download | async-ff06a8283458db5624447f99d2c359e1711b8c99.tar.gz |
Support dynamic arguments in async.constant (ref. #1016)
-rw-r--r-- | lib/constant.js | 5 | ||||
-rw-r--r-- | mocha_test/constant.js | 28 |
2 files changed, 31 insertions, 2 deletions
diff --git a/lib/constant.js b/lib/constant.js index 706507f..ecaff80 100644 --- a/lib/constant.js +++ b/lib/constant.js @@ -4,7 +4,8 @@ import rest from 'lodash/rest'; export default rest(function(values) { var args = [null].concat(values); - return function (cb) { - return cb.apply(this, args); + return function () { + var callback = [].slice.call(arguments).pop(); + return callback.apply(this, args); }; }); diff --git a/mocha_test/constant.js b/mocha_test/constant.js new file mode 100644 index 0000000..d76076c --- /dev/null +++ b/mocha_test/constant.js @@ -0,0 +1,28 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe('constant', function () { + + it('basic usage', function(done){ + var f = async.constant(42, 1, 2, 3); + f(function (err, value, a, b, c) { + expect(err).to.equal(null); + expect(value).to.equal(42); + expect(a).to.equal(1); + expect(b).to.equal(2); + expect(c).to.equal(3); + done(); + }); + }); + + it('called with multiple arguments', function(done){ + var f = async.constant(42, 1, 2, 3); + f('argument to ignore', 'another argument', function (err, value, a) { + expect(err).to.equal(null); + expect(value).to.equal(42); + expect(a).to.equal(1); + done(); + }); + }); + +}); |