diff options
author | Caolan McMahon <caolan@caolanmcmahon.com> | 2014-03-28 15:02:50 +0000 |
---|---|---|
committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2014-03-28 15:02:50 +0000 |
commit | 1513f799ddf351473d01172626eaa4935e11cfa1 (patch) | |
tree | ad6fe1143f8154268e73134f645635a471e58fc0 /test/test-async.js | |
parent | e5ae810dbe4ee82701c947bc4cf5425d0bedeef1 (diff) | |
parent | 49faae6018261a8b925d8f507784ad2789d06376 (diff) | |
download | async-1513f799ddf351473d01172626eaa4935e11cfa1.tar.gz |
Merge remote-tracking branch 'ognivo/feature-seq'
Conflicts:
README.md
Diffstat (limited to 'test/test-async.js')
-rwxr-xr-x | test/test-async.js | 87 |
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'}]; |