From aa3fbfeedfd780aa1b39e333a7f56a2534ffd977 Mon Sep 17 00:00:00 2001 From: webbiesdk Date: Mon, 13 Mar 2017 10:34:06 +0100 Subject: Make async.transform actually support 2 arguments The documentation suggests that both the `accumulator` and `callback` arguments to transform is optional. However, if both are left out (and transform therefore is called with only 2 arguments), transform crashes with a `iteratee is not a function` exception. This fixes that. --- lib/transform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) ? [] : {}; -- cgit v1.2.1 From d7bc2380cfd861cc363d601e12a1cc0c74d18fd8 Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Mon, 13 Mar 2017 11:01:33 +0100 Subject: Added test for calling transform with two arguments --- mocha_test/transform.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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(); + } + }); }); -- cgit v1.2.1 From 3e8377da4e19c09cc9e7c819847e9551833cab8a Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Tue, 14 Mar 2017 09:59:07 +0100 Subject: Added test for filter with an object-collection, where the filtering fails. To improve coverage. --- mocha_test/filter.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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(); + }) + }); }); -- cgit v1.2.1