Can't return more than one value from a sinon stub
<p>I have a method that I want to stub using sinon, so that the first time it is called it returns one value, and then returns a different value on the second call. However currently only the first value is being returned. My code is in Typescript and uses Sinon and Bluebird (promises).</p>

<pre><code>import sinon = require('sinon')
import * as MyService from "../main/Service"
import * as Promise from "bluebird"

it("test things", function(done) {
  let serviceStub = sinon.stub(MyService, 'method')

  serviceStub.onFirstCall().returns(Promise.reject("rejected"))
    .onSecondCall().returns(Promise.resolve("resolved"))

  MyService.method().then(function(value) {
    console.log("success 1: "+value.value())
  }, function(error) {
    console.log("error 1: "+error)
  })

  MyService.method().then(function(value) {
    console.log("success 2: "+value.value())
  }, function(error) {
    console.log("error 2: "+error)
  })

  done()
})
</code></pre>

<p>I presume I must be doing something wrong with the stubbing as this is the first time I have used sinon. If it returns <code>Promise.reject("rejected")</code> and then <code>Promise.resolve("resolved")</code> as I would expect it to, it would have the following output.</p>

<pre><code>error 1: rejected
success 2: resolved
</code></pre>

<p>However it just prints out the same error both times, so the <code>onSecondCall()</code> method isn't working. The first value I gave it, <code>Promise.reject("rejected")</code>, is being returned both times the method is called.</p>

<pre><code>error 1: rejected
error 2: rejected
</code></pre>

<p>Does anyone know what I'm doing wrong with my stubbing?</p>

<p>Note: For anyone unfamiliar with bluebird/promises, in the method <code>then(function(value){}, function(error){})</code> the first function handles what happens if the promise is resolved and the second function handles what happens if the promise is rejected . </p>