From 868c4ef9c31fa403ce7ffc7552b88d5410cc690c Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 20 Feb 2015 18:06:07 -0300 Subject: [PATCH] add async test --- .jshintrc | 5 ++++- test/eventbus.js | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.jshintrc b/.jshintrc index 40fd8c6f..73413260 100644 --- a/.jshintrc +++ b/.jshintrc @@ -41,5 +41,8 @@ "it", "module", "require" - ] + ], + "globals" : { + "Promise" : true + } } diff --git a/test/eventbus.js b/test/eventbus.js index ccd74df5..7e2a5846 100644 --- a/test/eventbus.js +++ b/test/eventbus.js @@ -4,8 +4,9 @@ var chai = require('chai'); var should = chai.should(); var sinon = require('sinon'); +var Promise = require('bluebird'); var EventBus = require('../lib/eventbus'); -require('bluebird').longStackTraces(); +Promise.longStackTraces(); describe('EventBus', function() { @@ -55,12 +56,12 @@ describe('EventBus', function() { }); bus.process(foo); }); + var b1 = new BarEvent(); + var b2 = new BarEvent(); it('foo returns two bars', function() { var bus = new EventBus(); var spy = sinon.spy(); bus.register(FooEvent, function() { - var b1 = new BarEvent(); - var b2 = new BarEvent(); return [b1, b2]; }); bus.register(BarEvent, spy); @@ -69,8 +70,6 @@ describe('EventBus', function() { }); it('foo returns two bars and emits external events', function(cb) { var bus = new EventBus(); - var b1 = new BarEvent(); - var b2 = new BarEvent(); var spy = sinon.spy(bus, 'emit'); bus.register(FooEvent, function() { return [b1, b2]; @@ -82,6 +81,19 @@ describe('EventBus', function() { }) .then(cb); }); + it('foo returns two async bars', function(cb) { + var bus = new EventBus(); + var spy = sinon.spy(); + bus.register(FooEvent, function() { + return Promise.resolve([b1, b2]).delay(1); + }); + bus.register(BarEvent, spy); + bus.process(foo) + .then(function() { + spy.callCount.should.equal(2); + }) + .then(cb); + }); }); });