summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2016-05-31 15:45:22 -0700
committerAlexander Early <alexander.early@gmail.com>2016-05-31 15:45:22 -0700
commit345dff499ac5f1995061aeeb2ab6300454dcaf7f (patch)
tree1d74a9d63199678746e73f5fa45320ea28b4663d /mocha_test
parentdf34c15003489a3bed056278bf7d14394e5f85cc (diff)
downloadasync-345dff499ac5f1995061aeeb2ab6300454dcaf7f.tar.gz
added mapValues
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/mapValues.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/mocha_test/mapValues.js b/mocha_test/mapValues.js
new file mode 100644
index 0000000..3938be2
--- /dev/null
+++ b/mocha_test/mapValues.js
@@ -0,0 +1,92 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var assert = require('assert');
+
+describe('mapValues', function () {
+ var obj = {a: 1, b: 2, c: 3};
+
+ context('mapValuesLimit', function () {
+ it('basics', function (done) {
+ var running = 0
+ var concurrency = {
+ a: 2,
+ b: 2,
+ c: 1
+ }
+ async.mapValuesLimit(obj, 2, function (val, key, next) {
+ running++;
+ async.setImmediate(function () {
+ expect(running).to.equal(concurrency[key]);
+ running--;
+ next(null, key + val);
+ });
+ }, function (err, result) {
+ expect(running).to.equal(0)
+ expect(err).to.eql(null);
+ expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'})
+ done();
+ });
+ });
+
+ it('error', function (done) {
+ async.mapValuesLimit(obj, 1, function(val, key, next) {
+ if (key === 'b') {
+ return next(new Error("fail"));
+ }
+ next(null, val);
+ }, function (err, result) {
+ expect(err).to.not.eql(null);
+ expect(result).to.eql({a: 1});
+ done();
+ });
+ });
+ });
+
+ context('mapValues', function () {
+ it('basics', function (done) {
+ var running = 0
+ var concurrency = {
+ a: 3,
+ b: 2,
+ c: 1
+ }
+ async.mapValues(obj, function (val, key, next) {
+ running++;
+ async.setImmediate(function () {
+ expect(running).to.equal(concurrency[key]);
+ running--;
+ next(null, key + val);
+ });
+ }, function (err, result) {
+ expect(running).to.equal(0)
+ expect(err).to.eql(null);
+ expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'})
+ done();
+ });
+ });
+ });
+
+ context('mapValuesSeries', function () {
+ it('basics', function (done) {
+ var running = 0
+ var concurrency = {
+ a: 1,
+ b: 1,
+ c: 1
+ }
+ async.mapValuesSeries(obj, function (val, key, next) {
+ running++;
+ async.setImmediate(function () {
+ expect(running).to.equal(concurrency[key]);
+ running--;
+ next(null, key + val);
+ });
+ }, function (err, result) {
+ expect(running).to.equal(0)
+ expect(err).to.eql(null);
+ expect(result).to.eql({a: 'a1', b: 'b2', c: 'c3'})
+ done();
+ });
+ });
+ });
+});