summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2016-03-09 13:07:33 -0800
committerAlex Early <alexander.early@gmail.com>2016-03-09 13:07:33 -0800
commitb5ea2b1cd0d01a45aa155663808f0cdf46ff1fe9 (patch)
tree301e8e0b2f165eba1d06ef32870294d775884b55 /mocha_test
parent5aadb0da9d738a3cf715599c982a1ae29aff9797 (diff)
parentdf31042d689ba51e383209b2836ad971c11dee07 (diff)
downloadasync-b5ea2b1cd0d01a45aa155663808f0cdf46ff1fe9.tar.gz
Merge pull request #1055 from caolan/autoinject
autoInject
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/autoInject.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js
new file mode 100644
index 0000000..53a3d17
--- /dev/null
+++ b/mocha_test/autoInject.js
@@ -0,0 +1,77 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var _ = require('lodash');
+
+describe('autoInject', function () {
+
+ it("basics", function (done) {
+ var callOrder = [];
+ async.autoInject({
+ task1: function(task2, callback){
+ expect(task2).to.equal(2);
+ setTimeout(function(){
+ callOrder.push('task1');
+ callback(null, 1);
+ }, 25);
+ },
+ task2: function(callback){
+ setTimeout(function(){
+ callOrder.push('task2');
+ callback(null, 2);
+ }, 50);
+ },
+ task3: function(task2, callback){
+ expect(task2).to.equal(2);
+ callOrder.push('task3');
+ callback(null, 3);
+ },
+ task4: function(task1, task2, callback){
+ expect(task1).to.equal(1);
+ expect(task2).to.equal(2);
+ callOrder.push('task4');
+ callback(null, 4);
+ },
+ task5: function(task2, callback){
+ expect(task2).to.equal(2);
+ setTimeout(function(){
+ callOrder.push('task5');
+ callback(null, 5);
+ }, 0);
+ },
+ task6: function(task2, callback){
+ expect(task2).to.equal(2);
+ callOrder.push('task6');
+ callback(null, 6);
+ }
+ },
+ function(err, results){
+ expect(results.task6).to.equal(6);
+ expect(callOrder).to.eql(['task2','task6','task3','task5','task1','task4']);
+ done();
+ });
+ });
+
+ it('should work with array tasks', function (done) {
+ var callOrder = [];
+
+ async.autoInject({
+ task1: function (cb) {
+ callOrder.push('task1');
+ cb(null, 1);
+ },
+ task2: ['task3', function (task3, cb) {
+ expect(task3).to.equal(3);
+ callOrder.push('task2');
+ cb(null, 2);
+ }],
+ task3: function (cb) {
+ callOrder.push('task3');
+ cb(null, 3);
+ }
+ }, function () {
+ expect(callOrder).to.eql(['task1','task3','task2']);
+ done();
+ });
+ });
+
+});