Using Sinon Stubs

sinonjs
const events = require('events');function pleaseTestMe(a, b, c) {
...
events.sendBigDealEvent(a, c, x); // test that it was called!
...
return something;
}
describe('Testing pleaseTestMe()', () => {
let a = 1, b = 2, ...
...

it('Test that sendBigDealEvent() was called correctly', () => {
const sendBigDealEvent = sinon.stub(events, 'sendBigDealEvent');
pleaseTestMe(a, b, c);
sinon.assert.calledOnce(sendBigDealEvent);
sinon.assert.calledWith(sendBigDealEvent,
sinon.match(a, c, sinon.match.any));
sendBigDealEvent.restore();
});
...
});
const sendBigDealEvent = sinon.stub(events, 'sendBigDealEvent');
sinon.assert.calledWith(sendBigDealEvent, 
sinon.match(a, c, sinon.match.any));
sendBigDealEvent.restore();
Attempted to wrap someObj which is already wrapped

--

--

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store