Skip to content

Instantly share code, notes, and snippets.

@Farenheith
Last active February 22, 2020 16:57
Show Gist options
  • Save Farenheith/61eaf5338f2ba490eafdeedecd57f99b to your computer and use it in GitHub Desktop.
Save Farenheith/61eaf5338f2ba490eafdeedecd57f99b to your computer and use it in GitHub Desktop.
import { EventEmitter } from 'events';
import { expect } from 'chai';
import { stub } from 'sinon';
import { eventEmitterExample } from '../src/event-emitter-example';
describe.only('eventEmitterExample()', () => {
beforeEach(() => {
stub(console, 'info');
stub(console, 'error');
});
it('shoud log info something that happen when somethingHappen is emitted', () => {
const emitter = new EventEmitter();
const result = eventEmitterExample(emitter);
emitter.emit('somethingHappen', 'You got what you want!');
expect(console.info).to.have.been.calledOnceWithExactly('Something happened! You got what you want!');
expect(console.error).to.have.not.been.called;
expect(result).to.be.undefined;
});
it('shoud log error something went wrong when sometingGoesWrong is emitted', () => {
const emitter = new EventEmitter();
const result = eventEmitterExample(emitter);
emitter.emit('sometingGoesWrong', 'You got what you deserve!');
expect(console.info).to.have.not.been.called;
expect(console.error).to.have.been.calledOnceWithExactly('Something went wrong! You got what you deserve!');
expect(result).to.be.undefined;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment