add async test

This commit is contained in:
Manuel Araoz 2015-02-20 18:06:07 -03:00
parent cdf8dab86c
commit 868c4ef9c3
2 changed files with 21 additions and 6 deletions

View File

@ -41,5 +41,8 @@
"it",
"module",
"require"
]
],
"globals" : {
"Promise" : true
}
}

View File

@ -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);
});
});
});