diff options
Diffstat (limited to 'test/map.js')
-rw-r--r-- | test/map.js | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/test/map.js b/test/map.js index eb0c3ea..c104ab9 100644 --- a/test/map.js +++ b/test/map.js @@ -2,10 +2,10 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); -describe("map", function() { +describe("map", () => { function mapIteratee(call_order, x, callback) { - setTimeout(function() { + setTimeout(() => { call_order.push(x); callback(null, x * 2); }, x * 25); @@ -13,7 +13,7 @@ describe("map", function() { it('basic', function(done) { var call_order = []; - async.map([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + async.map([1, 3, 2], mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 2, 3]); expect(results).to.eql([2, 6, 4]); @@ -21,14 +21,14 @@ describe("map", function() { }); }); - it('with reflect', function(done) { + it('with reflect', (done) => { var call_order = []; - async.map([1, 3, 2], async.reflect(function(item, cb) { - setTimeout(function() { + async.map([1, 3, 2], async.reflect((item, cb) => { + setTimeout(() => { call_order.push(item); cb(null, item * 2); }, item * 25); - }), function(err, results) { + }), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 2, 3]); expect(results).to.eql([{ @@ -42,10 +42,10 @@ describe("map", function() { }); }); - it('error with reflect', function(done) { + it('error with reflect', (done) => { var call_order = []; - async.map([-1, 1, 3, 2], async.reflect(function(item, cb) { - setTimeout(function() { + async.map([-1, 1, 3, 2], async.reflect((item, cb) => { + setTimeout(() => { call_order.push(item); if (item < 0) { cb('number less then zero'); @@ -53,7 +53,7 @@ describe("map", function() { cb(null, item * 2); } }, item * 25); - }), function(err, results) { + }), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([-1, 1, 2, 3]); expect(results).to.eql([{ @@ -69,21 +69,21 @@ describe("map", function() { }); }); - it('map original untouched', function(done) { + it('map original untouched', (done) => { var a = [1, 2, 3]; - async.map(a, function(x, callback) { + async.map(a, (x, callback) => { callback(null, x * 2); - }, function(err, results) { + }, (err, results) => { expect(results).to.eql([2, 4, 6]); expect(a).to.eql([1, 2, 3]); done(); }); }); - it('map without main callback', function(done) { + it('map without main callback', (done) => { var a = [1, 2, 3]; var r = []; - async.map(a, function(x, callback) { + async.map(a, (x, callback) => { r.push(x); var done_ = r.length == a.length; callback(null); @@ -94,35 +94,35 @@ describe("map", function() { }); }); - it('map error', function(done) { - async.map([1, 2, 3], function(x, callback) { + it('map error', (done) => { + async.map([1, 2, 3], (x, callback) => { callback('error'); - }, function(err) { + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('map undefined array', function(done) { - async.map(undefined, function(x, callback) { + it('map undefined array', (done) => { + async.map(undefined, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); setTimeout(done, 50); }); - it('map object', function(done) { + it('map object', (done) => { async.map({ a: 1, b: 2, c: 3 - }, function(val, callback) { + }, (val, callback) => { callback(null, val * 2); - }, function(err, result) { + }, (err, result) => { if (err) throw err; - expect(Object.prototype.toString.call(result)).to.equal('[object Array]'); + expect(Array.isArray(result)).to.equal(true); expect(result).to.contain(2); expect(result).to.contain(4); expect(result).to.contain(6); @@ -132,7 +132,7 @@ describe("map", function() { it('mapSeries', function(done) { var call_order = []; - async.mapSeries([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + async.mapSeries([1, 3, 2], mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([1, 3, 2]); expect(results).to.eql([2, 6, 4]); @@ -140,33 +140,33 @@ describe("map", function() { }); }); - it('mapSeries error', function(done) { - async.mapSeries([1, 2, 3], function(x, callback) { + it('mapSeries error', (done) => { + async.mapSeries([1, 2, 3], (x, callback) => { callback('error'); - }, function(err) { + }, (err) => { expect(err).to.equal('error'); }); setTimeout(done, 50); }); - it('mapSeries undefined array', function(done) { - async.mapSeries(undefined, function(x, callback) { + it('mapSeries undefined array', (done) => { + async.mapSeries(undefined, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); setTimeout(done, 50); }); - it('mapSeries object', function(done) { + it('mapSeries object', (done) => { async.mapSeries({ a: 1, b: 2, c: 3 - }, function(val, callback) { + }, (val, callback) => { callback(null, val * 2); - }, function(err, result) { + }, (err, result) => { if (err) throw err; expect(result).to.contain(2); expect(result).to.contain(4); @@ -177,7 +177,7 @@ describe("map", function() { it('mapLimit', function(done) { var call_order = []; - async.mapLimit([2, 4, 3], 2, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([2, 4, 3], 2, mapIteratee.bind(this, call_order), (err, results) => { assert(err === null, err + " passed instead of 'null'"); expect(call_order).to.eql([2, 4, 3]); expect(results).to.eql([4, 8, 6]); @@ -185,21 +185,21 @@ describe("map", function() { }); }); - it('mapLimit empty array', function(done) { - async.mapLimit([], 2, function(x, callback) { + it('mapLimit empty array', (done) => { + async.mapLimit([], 2, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function(err) { + }, (err) => { if (err) throw err; assert(true, 'should call callback'); }); setTimeout(done, 25); }); - it('mapLimit undefined array', function(done) { - async.mapLimit(undefined, 2, function(x, callback) { + it('mapLimit undefined array', (done) => { + async.mapLimit(undefined, 2, (x, callback) => { callback(); - }, function(err, result) { + }, (err, result) => { expect(err).to.equal(null); expect(result).to.eql([]); }); @@ -208,7 +208,7 @@ describe("map", function() { it('mapLimit limit exceeds size', function(done) { var call_order = []; - async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 20, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 20, mapIteratee.bind(this, call_order), (err, results) => { expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); done(); @@ -217,90 +217,90 @@ describe("map", function() { it('mapLimit limit equal size', function(done) { var call_order = []; - async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, mapIteratee.bind(this, call_order), function(err, results) { + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, mapIteratee.bind(this, call_order), (err, results) => { expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); done(); }); }); - it('mapLimit zero limit', function() { + it('mapLimit zero limit', () => { expect(() => { - async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { + async.mapLimit([0, 1, 2, 3, 4, 5], 0, (x, callback) => { assert(false, 'iteratee should not be called'); callback(); - }, function() { + }, () => { assert(false, 'should not be called'); }); }).to.throw(/concurrency limit/) }); - it('mapLimit error', function(done) { + it('mapLimit error', (done) => { var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var call_order = []; - async.mapLimit(arr, 3, function(x, callback) { + async.mapLimit(arr, 3, (x, callback) => { call_order.push(x); if (x === 2) { callback('error'); } - }, function(err) { + }, (err) => { expect(call_order).to.eql([0, 1, 2]); expect(err).to.equal('error'); }); setTimeout(done, 25); }); - it('mapLimit does not continue replenishing after error', function(done) { + it('mapLimit does not continue replenishing after error', (done) => { var started = 0; var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var delay = 10; var limit = 3; var maxTime = 10 * arr.length; - async.mapLimit(arr, limit, function(x, callback) { + async.mapLimit(arr, limit, (x, callback) => { started++; if (started === 3) { return callback(new Error("Test Error")); } - setTimeout(function() { + setTimeout(() => { callback(); }, delay); - }, function() {}); + }, () => {}); - setTimeout(function() { + setTimeout(() => { expect(started).to.equal(3); done(); }, maxTime); }); - it('map with Map', function(done) { + it('map with Map', (done) => { if (typeof Map !== 'function') return done(); var map = new Map(); map.set(1, "a"); map.set(2, "b"); - async.map(map, function(val, cb) { + async.map(map, (val, cb) => { cb(null, val); - }, function(err, result) { + }, (err, result) => { assert(Array.isArray(result), "map should return an array for an iterable"); done(); }); }); // Issue 1106 on github: https://github.com/caolan/async/issues/1106 - it('map main callback is called only once', function(done) { - async.map([1, 2], function(item, callback) { + it('map main callback is called only once', (done) => { + async.map([1, 2], (item, callback) => { try { callback(item); } catch (exception) { - expect(function() { + expect(() => { callback(exception); }).to.throw(/already called/); done(); } - }, function() { + }, () => { throw new Error(); }); }); |