chai-eventemitter NPM Version Build Status

This is a plugin for chai to simplify the testing of EventEmitter.

EventEmitters can be testing using spies, but they are rather heavyweight for most usecases:

var spy = sinon.spy()

ee.on('test', spy)
ee.emit('test')
expect(spy).to.have.been.called()

spy.reset()
ee.emit('test', args)
expect(spy).to.have.been.calledWith(args)

chai-eventemitter replaces this with something much more digestable:

expect(function(){ ee.emit('test') }).to.emitFrom(ee, 'test')
expect(function(){ ee.emit('test', arg) }).to.emitFrom(ee, 'test', arg)

Setup

node.js / io.js

var chai = require('chai')
chai.use(require('chai-eventemitter'))

Browser

<script src="chai.js"></script>
<script src="chai-eventemitter.js"></script>

License

chai-eventemitter is released under the MIT License