Using Sinon, how does one stub an entire object and all of its methods and then replace them with another object?
I have tried something like this, but it doesnt seem to work:
var stubby = sinon.stub(stubbedObj);
stubby.returns(newReplacementObj);
console.log(stubby); // this returns stub, but it would think that it should return newReplacementObj?
You could also consider refactoring your code to call a function that you can then stub instead. Example instead of stubbing out window.something, you can make an accessor method that uses window.something, and then stub out that accessor method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With