Javascript: Mocking Constructor using Sinon
I needed a solution for this because my code was calling the new operator. I wanted to mock the object that the new call created. var MockExample = sinon.stub(); MockExample.prototype.test = sinon.stub().returns(“42”); var example = new MockExample(); console.log(“example: ” + example.test()); // outputs 42 Then I used rewire to inject it into the code that …