summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorezubarev <zubarev.eugene@gmail.com>2016-05-06 13:37:24 +0600
committerezubarev <zubarev.eugene@gmail.com>2016-05-06 13:37:24 +0600
commit6dc73a3e0454a8c02d3b996bc908860c82d21f84 (patch)
treee41636ec4782da5c5205410ed5e52a625ff536cd
parente17f3d7d534dc6bf9aad530c3a3e77924a9070fe (diff)
downloadasync-6dc73a3e0454a8c02d3b996bc908860c82d21f84.tar.gz
Convert apply/concat tests to mocha
-rw-r--r--mocha_test/apply.js21
-rw-r--r--mocha_test/concat.js57
-rwxr-xr-xtest/test-async.js84
3 files changed, 78 insertions, 84 deletions
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();
- });
-};