From be9346438fbd62fa87bec02f58bdd693afbe153f Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Sat, 26 Nov 2011 13:48:09 +0100 Subject: [PATCH] removed spacing & should --- tests/eventreactor.test.js | 187 ++++++++++++++++++------------------- 1 file changed, 93 insertions(+), 94 deletions(-) diff --git a/tests/eventreactor.test.js b/tests/eventreactor.test.js index 0b0c6b2..6e33417 100644 --- a/tests/eventreactor.test.js +++ b/tests/eventreactor.test.js @@ -1,96 +1,95 @@ -var EventEmitter = process.EventEmitter - , should = require('should'); - - // initialize our module - require('../lib')(true); - - module.exports = { - 'has event': function () { - var EE = new EventEmitter - , example = function () {}; - - EE.on('example', example); - - // test this shizz - EE.has('example', example).should.be_true; - EE.has('testcase', example).should.be_false; - EE.has('example', function () {}).should.be_false; +var EventEmitter = process.EventEmitter; + +// initialize our module +require('../lib')(true); + +module.exports = { + 'has event': function () { + var EE = new EventEmitter + , example = function () {}; + + EE.on('example', example); + + // test this shizz + EE.has('example', example).should.be_true; + EE.has('testcase', example).should.be_false; + EE.has('example', function () {}).should.be_false; + } + + , 'subscribe to every given event': function () { + var EE = new EventEmitter + , count = 0; + + EE.every('events', 'here', 'could', 'be', 'fired', function () { + ++count; + }); + + EE.emit('events'); + EE.emit('here'); + EE.emit('could'); + EE.emit('be'); + EE.emit('fired'); + EE.emit('non existant'); + + // for some odd reason it seems like that the events are fired + // async, without a setTimeout it wines about 4 count's instead of 5 + setTimeout(function () { + count.should.equal(5); + }, 10); + } + + , 'capture non listening events': function () { + var EE = new EventEmitter + , count = 0 + , unexisting = [ + 'i dont exist' + , 'me neither' + , 'nor do i' + ] + , i = unexisting.length; + + EE.on('uncaught', function (event, data) { + unexisting.indexOf(event).should.be.above(-1); + count++; + }); + + EE.on('exists', function () {}); + + while (i--) EE.emit(unexisting[i]); + EE.emit('exists'); + + // see above for the odd timeout thingy + setTimeout(function () { + count.should.equal(3); + }, 10); + } + + , 'multiple event listeners': function () { + var EE = new EventEmitter + , count = 0; + + function listen () { + count++; } - , 'subscribe to every given event': function () { - var EE = new EventEmitter - , count = 0; - - EE.every('events', 'here', 'could', 'be', 'fired', function () { - ++count; - }); - - EE.emit('events'); - EE.emit('here'); - EE.emit('could'); - EE.emit('be'); - EE.emit('fired'); - EE.emit('non existant'); - - // for some odd reason it seems like that the events are fired - // async, without a setTimeout it wines about 4 count's instead of 5 - setTimeout(function () { - count.should.equal(5); - }, 10); - } - - , 'capture non listening events': function () { - var EE = new EventEmitter - , count = 0 - , unexisting = [ - 'i dont exist' - , 'me neither' - , 'nor do i' - ] - , i = unexisting.length; - - EE.on('uncaught', function (event, data) { - unexisting.indexOf(event).should.be.above(-1); - count++; - }); - - EE.on('exists', function () {}); - - while (i--) EE.emit(unexisting[i]); - EE.emit('exists'); - - // see above for the odd timeout thingy - setTimeout(function () { - count.should.equal(3); - }, 10); - } - - , 'multiple event listeners': function () { - var EE = new EventEmitter - , count = 0; - - function listen () { - count++; - } - - EE.multiple({ - error: listen - , timeout: listen - , disconnect: listen - , reconnect: listen - , abort: listen - }); - - // test to see if all events applied - EE.emit('error'); - EE.emit('timeout'); - EE.emit('disconnect'); - EE.emit('reconnect'); - EE.emit('abort'); - - // see above for the odd timeout thingy - setTimeout(function () { - count.should.equal(5); - }, 10); - } - }; + EE.multiple({ + error: listen + , timeout: listen + , disconnect: listen + , reconnect: listen + , abort: listen + }); + + // test to see if all events applied + EE.emit('error'); + EE.emit('timeout'); + EE.emit('disconnect'); + EE.emit('reconnect'); + EE.emit('abort'); + + // see above for the odd timeout thingy + setTimeout(function () { + count.should.equal(5); + }, 10); + } +};