Sinon.js, only stub a method once?
<p>I am wondering is there is a possibility in sinon.js to stub a method only once?</p>

<p>For example:</p>

<pre><code>sinon.stub(module, 'randomFunction', 'returnValue/function');
</code></pre>

<p>In my test this <em>module.randomFunction</em> will be called multiple times <em>in the same test</em>, but I only want the stub to trigger once and then restore it so the function goes back to its normal behaviour.</p>

<p>Simulation of the real code:</p>

<pre><code>myModule.putItem(item, function (err, data) {
  if (err) {
    // do stuff
    return callback();
  } else {
    // do other stuff
    return callback(null, data);
  }
});
</code></pre>

<p>The first time I want to trigger the error, the other times I just want it to continue the real flow.</p>

<p>Is this possible in sinon?</p>

<p>Kind regards,</p>

<p>Jimmy</p>

<p><em>Edit:</em> I posted a solution I found for my problem based on the answer of @Grimurd</p>