summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2017-03-14 10:13:49 -0400
committerGitHub <noreply@github.com>2017-03-14 10:13:49 -0400
commit3d7974562bc1da172b9cc60f7759079ab522ea9a (patch)
tree5ed6665242a0bf3863291df6fefe0ae3675677bb
parentbdc3d814b3eb574fa6ab2824fc19b3acf0c35d2c (diff)
parent3e8377da4e19c09cc9e7c819847e9551833cab8a (diff)
downloadasync-3d7974562bc1da172b9cc60f7759079ab522ea9a.tar.gz
Merge pull request #1381 from webbiesdk/patch-1
Make async.transform actually support 2 arguments
-rw-r--r--lib/transform.js2
-rw-r--r--mocha_test/filter.js13
-rw-r--r--mocha_test/transform.js11
3 files changed, 25 insertions, 1 deletions
diff --git a/lib/transform.js b/lib/transform.js
index 5d1342a..f001c51 100644
--- a/lib/transform.js
+++ b/lib/transform.js
@@ -50,7 +50,7 @@ import once from './internal/once';
* })
*/
export default function transform (coll, accumulator, iteratee, callback) {
- if (arguments.length === 3) {
+ if (arguments.length <= 3) {
callback = iteratee;
iteratee = accumulator;
accumulator = isArray(coll) ? [] : {};
diff --git a/mocha_test/filter.js b/mocha_test/filter.js
index 8f13620..a6cea2a 100644
--- a/mocha_test/filter.js
+++ b/mocha_test/filter.js
@@ -172,4 +172,17 @@ describe("reject", function () {
});
});
+ it('filter fails', function(done) {
+ async.filter({a: 1, b: 2, c: 3}, function (item, callback) {
+ if (item === 3) {
+ callback("error", false);
+ } else {
+ callback(null, true);
+ }
+ }, function (err, res) {
+ expect(err).to.equal("error");
+ expect(res).to.equal(undefined);
+ done();
+ })
+ });
});
diff --git a/mocha_test/transform.js b/mocha_test/transform.js
index 5c04f56..a02b54b 100644
--- a/mocha_test/transform.js
+++ b/mocha_test/transform.js
@@ -51,4 +51,15 @@ describe('transform', function() {
done();
});
});
+
+ it('transform with two arguments', function(done) {
+ try {
+ async.transform([1, 2, 3], function (a, v, k, callback) {
+ callback();
+ });
+ done();
+ } catch (e) {
+ expect.fail();
+ }
+ });
});