Posted on April 15, 2014 by Chris Harrington

Stubbing included functions with Sinon while unit testing in Node

I’ve recently been on a unit testing bender with Leaf; I was able to get to 100% code coverage. I understand that while I might have 100% coverage, I might also have shitty tests, but I feel the inverse is also true: if I have 0% coverage, I most definitely have shitty tests. Either way, I ran into a few hurdles while writing all of these unit tests and I’d like to share how I got around one of them in particular. Most of the libraries that I require in Leaf expose a number of methods for me to use, which is great, because they’re easy to stub using Sinon, as such:

var getStub = sinon.stub(obj, "get");

Continue reading