sandbox = sinon.sandbox.create();
sandbox.stub(db, 'query', () => {
return Promise.resolve();
});
sandbox.stub(process, 'exit', () => { });
sandbox.restore();
removes all the stubs.
I want to remove ONE stub so I can restub it. For example the query
stub.
Is this possible? I can't find any information on this.
var stub = sinon. The original function can be restored by calling object. method. restore(); (or stub. restore(); ).
restore(); Restores all fakes created through sandbox.
The sinon. stub() substitutes the real function and returns a stub object that you can configure using methods like callsFake() . Stubs also have a callCount property that tells you how many times the stub was called. For example, the below code stubs out axios.
You can restore single method like this:
db.query.restore();
for your particular case.
Per sinon documentation:
var stub = sinon.stub(object, "method");
Replaces object.method with a stub function. An exception is thrown if the property is not already a function.
The original function can be restored by calling object.method.restore(); (or stub.restore();).
See http://sinonjs.org/releases/v2.3.6/stubs/
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