From 167a019496ba1b4e83f29ef502e4a7e2f056ba85 Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Thu, 7 Apr 2016 14:04:35 -0700 Subject: convert applyEach tests to mocha --- mocha_test/applyEach.js | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test-async.js | 92 ----------------------------------------------- 2 files changed, 96 insertions(+), 92 deletions(-) create mode 100644 mocha_test/applyEach.js diff --git a/mocha_test/applyEach.js b/mocha_test/applyEach.js new file mode 100644 index 0000000..d2080a6 --- /dev/null +++ b/mocha_test/applyEach.js @@ -0,0 +1,96 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('applyEach', function () { + + it('applyEach', function (done) { + var call_order = []; + var one = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('one'); + cb(null, 1); + }, 10); + }; + var two = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('two'); + cb(null, 2); + }, 5); + }; + var three = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('three'); + cb(null, 3); + }, 15); + }; + async.applyEach([one, two, three], 5, function (err) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql(['two', 'one', 'three']); + done(); + }); + }); + + it('applyEachSeries', function (done) { + var call_order = []; + var one = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('one'); + cb(null, 1); + }, 10); + }; + var two = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('two'); + cb(null, 2); + }, 5); + }; + var three = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('three'); + cb(null, 3); + }, 15); + }; + async.applyEachSeries([one, two, three], 5, function (err) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql(['one', 'two', 'three']); + done(); + }); + }); + + it('applyEach partial application', function (done) { + var call_order = []; + var one = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('one'); + cb(null, 1); + }, 10); + }; + var two = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('two'); + cb(null, 2); + }, 5); + }; + var three = function (val, cb) { + expect(val).to.equal(5); + setTimeout(function () { + call_order.push('three'); + cb(null, 3); + }, 15); + }; + async.applyEach([one, two, three])(5, function (err) { + if (err) throw err; + expect(call_order).to.eql(['two', 'one', 'three']); + done(); + }); + }); +}); diff --git a/test/test-async.js b/test/test-async.js index b77ba78..b310f70 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -78,98 +78,6 @@ function isBrowser() { (process + "" !== "[object process]"); // browserify } -exports['applyEach'] = function (test) { - test.expect(5); - var call_order = []; - var one = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('one'); - cb(null, 1); - }, 100); - }; - var two = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('two'); - cb(null, 2); - }, 50); - }; - var three = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('three'); - cb(null, 3); - }, 150); - }; - async.applyEach([one, two, three], 5, function (err) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, ['two', 'one', 'three']); - test.done(); - }); -}; - -exports['applyEachSeries'] = function (test) { - test.expect(5); - var call_order = []; - var one = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('one'); - cb(null, 1); - }, 100); - }; - var two = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('two'); - cb(null, 2); - }, 50); - }; - var three = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('three'); - cb(null, 3); - }, 150); - }; - async.applyEachSeries([one, two, three], 5, function (err) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, ['one', 'two', 'three']); - test.done(); - }); -}; - -exports['applyEach partial application'] = function (test) { - test.expect(4); - var call_order = []; - var one = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('one'); - cb(null, 1); - }, 100); - }; - var two = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('two'); - cb(null, 2); - }, 50); - }; - var three = function (val, cb) { - test.equal(val, 5); - setTimeout(function () { - call_order.push('three'); - cb(null, 3); - }, 150); - }; - async.applyEach([one, two, three])(5, function (err) { - if (err) throw err; - test.same(call_order, ['two', 'one', 'three']); - test.done(); - }); -}; exports['seq'] = function (test) { test.expect(5); -- cgit v1.2.1