diff options
author | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 13:20:40 +0600 |
---|---|---|
committer | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 13:20:40 +0600 |
commit | d474084c90a60648fea6900ea5376d76c74bc222 (patch) | |
tree | 9766372d4ebadf8b53fb61dd07493f6b8d8322fd /mocha_test/until.js | |
parent | 764600eef0801abd7afbd9cd2a0878c17c3a101e (diff) | |
download | async-d474084c90a60648fea6900ea5376d76c74bc222.tar.gz |
Convert sortBy/whilst/until tests to mocha
Diffstat (limited to 'mocha_test/until.js')
-rw-r--r-- | mocha_test/until.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/mocha_test/until.js b/mocha_test/until.js new file mode 100644 index 0000000..a738218 --- /dev/null +++ b/mocha_test/until.js @@ -0,0 +1,93 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('until', function(){ + it('until', function(done) { + var call_order = []; + var count = 0; + async.until( + function () { + call_order.push(['test', count]); + return (count == 5); + }, + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['test', 0], + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5], + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doUntil', function(done) { + var call_order = []; + var count = 0; + async.doUntil( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function () { + call_order.push(['test', count]); + return (count == 5); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doUntil callback params', function(done) { + var call_order = []; + var count = 0; + async.doUntil( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (c) { + call_order.push(['test', c]); + return (c == 5); + }, + function (err, result) { + if (err) throw err; + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); +}); |