If I have create a instance by var a = sinon.createStubInstance(MyContructor).
How can I replace one of the stubbed function like var stub = sinon.stub(object, "method", func);.
The main reason I am doing this is want to achieve multiple callback workaround as this mentioned
The method you mentioned (
sinon.stub(object, "method", func)) is a method that was available in version 1.x, and did the following according to the documentation:However, if you're using
sinon.createStubInstance(), all methods are already stubbed. That means you can already do certain things with the stubbed instance. For example:If you really want to replace a stub by another spy or stub, you could assign the property to a new stub or spy:
With Sinon.js 2.x and higher, it's even easier to replace a stubbed function by using the
callsFake()function: