Last active
February 22, 2020 16:57
-
-
Save Farenheith/61eaf5338f2ba490eafdeedecd57f99b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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