I am wondering is there is a possibility in sinon.js to stub a method only once?
For example:
sinon.stub(module, 'randomFunction', 'returnValue/function');
In my test this module.randomFunction will be called multiple times in the same test, but I only want the stub to trigger once and then restore it so the function goes back to its normal behaviour.
Simulation of the real code:
myModule.putItem(item, function (err, data) {
if (err) {
// do stuff
return callback();
} else {
// do other stuff
return callback(null, data);
}
});
The first time I want to trigger the error, the other times I just want it to continue the real flow.
Is this possible in sinon?
Kind regards,
Jimmy
Edit: I posted a solution I found for my problem based on the answer of @Grimurd