summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2016-04-07 14:04:35 -0700
committerAlexander Early <alexander.early@gmail.com>2016-04-07 14:04:35 -0700
commit167a019496ba1b4e83f29ef502e4a7e2f056ba85 (patch)
treeedbefa63b559e87ccdd66f3d898a398152d6dbf4
parentb73480d50f0cad4f037cf2897a89fc46ffe2e01f (diff)
downloadasync-167a019496ba1b4e83f29ef502e4a7e2f056ba85.tar.gz
convert applyEach tests to mocha
-rw-r--r--mocha_test/applyEach.js96
-rwxr-xr-xtest/test-async.js92
2 files changed, 96 insertions, 92 deletions
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);