summaryrefslogtreecommitdiff
path: root/test/test-async.js
diff options
context:
space:
mode:
authorCaolan McMahon <caolan@caolanmcmahon.com>2014-03-28 15:02:50 +0000
committerCaolan McMahon <caolan@caolanmcmahon.com>2014-03-28 15:02:50 +0000
commit1513f799ddf351473d01172626eaa4935e11cfa1 (patch)
treead6fe1143f8154268e73134f645635a471e58fc0 /test/test-async.js
parente5ae810dbe4ee82701c947bc4cf5425d0bedeef1 (diff)
parent49faae6018261a8b925d8f507784ad2789d06376 (diff)
downloadasync-1513f799ddf351473d01172626eaa4935e11cfa1.tar.gz
Merge remote-tracking branch 'ognivo/feature-seq'
Conflicts: README.md
Diffstat (limited to 'test/test-async.js')
-rwxr-xr-xtest/test-async.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js
index d5b5508..539acc8 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -261,6 +261,93 @@ exports['compose binding'] = function (test) {
});
};
+exports['seq'] = function (test) {
+ test.expect(4);
+ var add2 = function (n, cb) {
+ test.equal(n, 3);
+ setTimeout(function () {
+ cb(null, n + 2);
+ }, 50);
+ };
+ var mul3 = function (n, cb) {
+ test.equal(n, 5);
+ setTimeout(function () {
+ cb(null, n * 3);
+ }, 15);
+ };
+ var add1 = function (n, cb) {
+ test.equal(n, 15);
+ setTimeout(function () {
+ cb(null, n + 1);
+ }, 100);
+ };
+ var add2mul3add1 = async.seq(add2, mul3, add1);
+ add2mul3add1(3, function (err, result) {
+ if (err) {
+ return test.done(err);
+ }
+ test.equal(result, 16);
+ test.done();
+ });
+};
+
+exports['seq error'] = function (test) {
+ test.expect(3);
+ var testerr = new Error('test');
+
+ var add2 = function (n, cb) {
+ test.equal(n, 3);
+ setTimeout(function () {
+ cb(null, n + 2);
+ }, 50);
+ };
+ var mul3 = function (n, cb) {
+ test.equal(n, 5);
+ setTimeout(function () {
+ cb(testerr);
+ }, 15);
+ };
+ var add1 = function (n, cb) {
+ test.ok(false, 'add1 should not get called');
+ setTimeout(function () {
+ cb(null, n + 1);
+ }, 100);
+ };
+ var add2mul3add1 = async.seq(add2, mul3, add1);
+ add2mul3add1(3, function (err, result) {
+ test.equal(err, testerr);
+ test.done();
+ });
+};
+
+exports['seq binding'] = function (test) {
+ test.expect(4);
+ var testerr = new Error('test');
+ var testcontext = {name: 'foo'};
+
+ var add2 = function (n, cb) {
+ test.equal(this, testcontext);
+ setTimeout(function () {
+ cb(null, n + 2);
+ }, 50);
+ };
+ var mul3 = function (n, cb) {
+ test.equal(this, testcontext);
+ setTimeout(function () {
+ cb(null, n * 3);
+ }, 15);
+ };
+ var add2mul3 = async.seq(add2, mul3);
+ add2mul3.call(testcontext, 3, function (err, result) {
+ if (err) {
+ return test.done(err);
+ }
+ test.equal(this, testcontext);
+ test.equal(result, 15);
+ test.done();
+ });
+};
+
exports['auto'] = function(test){
var callOrder = [];
var testdata = [{test: 'test'}];