diff options
author | Alex Early <alexander.early@gmail.com> | 2016-03-07 21:40:39 -0800 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2016-03-07 21:40:39 -0800 |
commit | 1a267301890bbc7222139c799dab050f83be0d24 (patch) | |
tree | 3d9bb1d0905ee48a515e8f0f81a5c48808fe2860 | |
parent | 07208a6003b49b4984ff8e205d37738192239319 (diff) | |
parent | ff06a8283458db5624447f99d2c359e1711b8c99 (diff) | |
download | async-1a267301890bbc7222139c799dab050f83be0d24.tar.gz |
Merge pull request #1052 from ajfranzoia/constant-dynamic-args
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(); + }); + }); + +}); |