Skip to content

Instantly share code, notes, and snippets.

@Unitech
Created May 15, 2014 15:57
Show Gist options
  • Save Unitech/b8411abcad87a30fd548 to your computer and use it in GitHub Desktop.
Save Unitech/b8411abcad87a30fd548 to your computer and use it in GitHub Desktop.
Testing events
var sinon = require('sinon')
, EventEmitter = require('events').EventEmitter;
describe('EventEmitter', function(){
describe('#emit()', function(){
it('should invoke the callback', function(){
var spy = sinon.spy()
, emitter = new EventEmitter;
emitter.on('foo', spy);
emitter.emit('foo');
spy.called.should.equal.true;
})
it('should pass arguments to the callbacks', function(){
var spy = sinon.spy()
, emitter = new EventEmitter;
emitter.on('foo', spy);
emitter.emit('foo', 'bar', 'baz');
sinon.assert.calledOnce(spy);
sinon.assert.calledWith(spy, 'bar', 'baz');
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment