From 6dc73a3e0454a8c02d3b996bc908860c82d21f84 Mon Sep 17 00:00:00 2001 From: ezubarev Date: Fri, 6 May 2016 13:37:24 +0600 Subject: Convert apply/concat tests to mocha --- mocha_test/apply.js | 21 +++++++++++++ mocha_test/concat.js | 57 +++++++++++++++++++++++++++++++++++ test/test-async.js | 84 ---------------------------------------------------- 3 files changed, 78 insertions(+), 84 deletions(-) create mode 100644 mocha_test/apply.js create mode 100644 mocha_test/concat.js diff --git a/mocha_test/apply.js b/mocha_test/apply.js new file mode 100644 index 0000000..18e5d12 --- /dev/null +++ b/mocha_test/apply.js @@ -0,0 +1,21 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe('concat', function() { + it('apply', function(done) { + var fn = function(){ + expect(Array.prototype.slice.call(arguments)).to.eql([1,2,3,4]); + }; + async.apply(fn, 1, 2, 3, 4)(); + async.apply(fn, 1, 2, 3)(4); + async.apply(fn, 1, 2)(3, 4); + async.apply(fn, 1)(2, 3, 4); + async.apply(fn)(1, 2, 3, 4); + expect( + async.apply(function(name){return 'hello ' + name;}, 'world')() + ).to.equal( + 'hello world' + ); + done(); + }); +}); diff --git a/mocha_test/concat.js b/mocha_test/concat.js new file mode 100644 index 0000000..389b2de --- /dev/null +++ b/mocha_test/concat.js @@ -0,0 +1,57 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('concat', function() { + it('concat', function(done) { + var call_order = []; + var iteratee = function (x, cb) { + setTimeout(function(){ + call_order.push(x); + var r = []; + while (x > 0) { + r.push(x); + x--; + } + cb(null, r); + }, x*25); + }; + async.concat([1,3,2], iteratee, function(err, results){ + expect(results).to.eql([1,2,1,3,2,1]); + expect(call_order).to.eql([1,2,3]); + assert(err === null, err + " passed instead of 'null'"); + done(); + }); + }); + + it('concat error', function(done) { + var iteratee = function (x, cb) { + cb(new Error('test error')); + }; + async.concat([1,2,3], iteratee, function(err){ + assert(err); + done(); + }); + }); + + it('concatSeries', function(done) { + var call_order = []; + var iteratee = function (x, cb) { + setTimeout(function(){ + call_order.push(x); + var r = []; + while (x > 0) { + r.push(x); + x--; + } + cb(null, r); + }, x*25); + }; + async.concatSeries([1,3,2], iteratee, function(err, results){ + expect(results).to.eql([1,3,2,1,2,1]); + expect(call_order).to.eql([1,3,2]); + assert(err === null, err + " passed instead of 'null'"); + done(); + }); + }); +}); diff --git a/test/test-async.js b/test/test-async.js index ba1a6f3..694f4bc 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -6,34 +6,6 @@ require('babel-core/register'); var async = require('../lib'); -if (!Function.prototype.bind) { - Function.prototype.bind = function (thisArg) { - var args = Array.prototype.slice.call(arguments, 1); - var self = this; - return function () { - self.apply(thisArg, args.concat(Array.prototype.slice.call(arguments))); - }; - }; -} - -exports['apply'] = function(test){ - test.expect(6); - var fn = function(){ - test.same(Array.prototype.slice.call(arguments), [1,2,3,4]); - }; - async.apply(fn, 1, 2, 3, 4)(); - async.apply(fn, 1, 2, 3)(4); - async.apply(fn, 1, 2)(3, 4); - async.apply(fn, 1)(2, 3, 4); - async.apply(fn)(1, 2, 3, 4); - test.equals( - async.apply(function(name){return 'hello ' + name;}, 'world')(), - 'hello world' - ); - test.done(); -}; - - // generates tests for console functions such as async.log var console_fn_tests = function(name){ @@ -100,59 +72,3 @@ console_fn_tests('dir'); /*console_fn_tests('info'); console_fn_tests('warn'); console_fn_tests('error');*/ - - -exports['concat'] = function(test){ - test.expect(3); - var call_order = []; - var iteratee = function (x, cb) { - setTimeout(function(){ - call_order.push(x); - var r = []; - while (x > 0) { - r.push(x); - x--; - } - cb(null, r); - }, x*25); - }; - async.concat([1,3,2], iteratee, function(err, results){ - test.same(results, [1,2,1,3,2,1]); - test.same(call_order, [1,2,3]); - test.ok(err === null, err + " passed instead of 'null'"); - test.done(); - }); -}; - -exports['concat error'] = function(test){ - test.expect(1); - var iteratee = function (x, cb) { - cb(new Error('test error')); - }; - async.concat([1,2,3], iteratee, function(err){ - test.ok(err); - test.done(); - }); -}; - -exports['concatSeries'] = function(test){ - test.expect(3); - var call_order = []; - var iteratee = function (x, cb) { - setTimeout(function(){ - call_order.push(x); - var r = []; - while (x > 0) { - r.push(x); - x--; - } - cb(null, r); - }, x*25); - }; - async.concatSeries([1,3,2], iteratee, function(err, results){ - test.same(results, [1,3,2,1,2,1]); - test.same(call_order, [1,3,2]); - test.ok(err === null, err + " passed instead of 'null'"); - test.done(); - }); -}; -- cgit v1.2.1