Skip to content

Commit

Permalink
Merge pull request #1381 from webbiesdk/patch-1
Browse files Browse the repository at this point in the history
Make async.transform actually support 2 arguments
  • Loading branch information
megawac committed Mar 14, 2017
2 parents bdc3d81 + 3e8377d commit 3d79745
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/transform.js
Expand Up @@ -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) ? [] : {};
Expand Down
13 changes: 13 additions & 0 deletions mocha_test/filter.js
Expand Up @@ -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();
})
});
});
11 changes: 11 additions & 0 deletions mocha_test/transform.js
Expand Up @@ -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();
}
});
});

0 comments on commit 3d79745

Please sign in to comment.