sinomocha
Sinon.JS integration for the Mocha test harness
Do you get annoyed when writing your Mocha tests with Sinon stubs - that you have to ceremoniously stub and restore methods in each test, like so:
; ;
Maybe you've discovered sinon sandboxes, but you still have the same rigmorale:
; ;
Well then look no further! This convinient wrapper will add stub
, spy
,
mock
, useFakeTimers
, useFakeServer
and useFakeXMLHttpRequest
to the
Mocha context, and automatically restores them in the right way. It seemlessly
works with before()
, beforeEach()
and it()
s so that it just works:
before()
spies/timers/requests will survive for the wholedescribe()
beforeEach()
spies/timers/requests will be reset for eachit()
it()
spies/timers/requests will live for the duration of that singleit()
Install
Simply add sinomocha
to your npm dependencies:
npm install --save sinomocha
Then require the method and run it (it require's sinon, so don't sweat it):
;
Examples
;;
Thanks
Thanks goes to Domenic Denicola's mocha as promised. This is based off of his original work.