title: Fake is not a spy
body: <p>So i have a method that calls an https request. i've successfully stubbed the calls in other tests but this one is beating me an it just won't work.</p>
  
  <p>in my beforeEach i create the stub
  in my afterEach i do stub restore</p>
  
  <p>in the test i create four stub calls.</p>
  
  <p><code>stub.onCall(0).callsFake((arg1, arg2, arg3, cb, arg5) =&gt; {return cb(null, {some object0})
  stub.onCall(1).callsFake((arg1, arg2, arg3, cb, arg5) =&gt; {return cb(null, {some object1})
  stub.onCall(2).callsFake((arg1, arg2, arg3, cb, arg5) =&gt; {return cb(null, {some object2})
  stub.onCall(3).callsFake((arg1, arg2, arg3, cb, arg5) =&gt; {return cb(null, {some object3})
  </code></p>
  
  <p>then after my ACT statement i attempt to assert the stubs are called with the correct parameters</p>
  
  <p><code>sinon.assert.calledWith(stub.firstCall, "blah","blah","blah",, sinon.match.any, "blah")
  sinon.assert.calledWith(stub.secondCall, "blah","blah","blah",, sinon.match.any, "blah", "blah")
  sinon.assert.calledWith(stub.thirdCall, "blah","blah","blah",, sinon.match.any, "blah")
  sinon.assert.calledWith(stub.call(3), "blah","blah","blah",, sinon.match.any, "blah"
  </code></p>
  
  <p>Unfortunately my test now reports</p>
  
  <p>AssertError: fake is not a spy</p>
  
  <p>I've console.logs in my code under test and they are reporting my stubs being called.</p>
  
  <p>a call to console.log(stub.callCount) return 1 not 4</p>
  
  <p>if i comment all but the first sinon.assert the test passes.</p>
  
  <p>So my question is what am i doing wrong</p>
  
  <p>I'll post my full setup below</p>
  
  <p>`    describe('Update Redis', () => {
          const balances = {
                  "TRTLv2Fyavy8CXG8BPEbNeCHFZ1fuDCYCZ3vW5H5LXN4K2M2MHUpTENip9bbavpHvvPwb4NDkBWrNgURAd5DB38FHXWZyoBh4w": 12000
          }
          const minPayoutLevel = {
                  "TRTLv2Fyavy8CXG8BPEbNeCHFZ1fuDCYCZ3vW5H5LXN4K2M2MHUpTENip9bbavpHvvPwb4NDkBWrNgURAd5DB38FHXWZyoBh4w": 10000
          }
          const endpoint1 = '/transactions/prepare/advanced'
          const endpoint2 = '/transactions/send/prepared'</p>
  
  <pre><code>    beforeEach(() =&gt; {
              stub = sinon.stub(apiInterfaces, 'jsonHttpRequest')
      })
  
      afterEach(() =&gt; {
              sinon.restore()
      })
  
      it("Should update workers balance, paid ,coin:payments:all and coin.payments.workers:address", () =&gt; {
              //ARRANGE
              let error = null
  
              const endpoint = '/transactions/prepare/advanced'
              const endpoint2 = '/transactions/send/prepared'
              stub.onCall(0)
                      .callsFake(function (host, port, data, callback, path) {
                              return callback(null,  {"transactionHash": "396e2a782c9ce9993982c6f93e305b05306d0e5794f57157fbac78581443c55f","fee": 1000,"relayedToNetwork": false})
                      })
              stub.onCall(1)
                      .callsFake(function (host, port, data, callback, path) {
                              return callback(null, null)
                      })
              stub.onCall(2)
                      .callsFake(function (host, port, data, callback, path) {
                              return callback(null, {"transactionHash": "396e2a782c9ce9993982c6f93e305b05306d0e5794f57157fbac78581443c55f","fee": 1000,"relayedToNetwork": false})
                      })
              stub.onCall(3)
                      .callsFake(function (host, port, data, callback, path) {
                              return callback(null, {
                                      "transactionHash": "396e2a782c9ce9993982c6f93e305b05306d0e5794f57157fbac78581443c55f"
                              })
                      })
  
              let callback = () =&gt; {return}
              //ACT
              coin.processPayments(balances, minPayoutLevel, callback)
              console.log(stub.callCount)
              sinon.assert.calledThrice(stub.jsonHttpRequest)
              sinon.assert.calledWith(stub.firstCall, config.wallet.host, config.wallet.port, '{"destinations":[{"amount":12000,"address":"TRTLv2Fyavy8CXG8BPEbNeCHFZ1fuDCYCZ3vW5H5LXN4K2M2MHUpTENip9bbavpHvvPwb4NDkBWrNgURAd5DB38FHXWZyoBh4w"}],"feePerByte":2,"unlock_time":0,"mixin":3}', sinon.match.any, endpoint1)
              sinon.assert.calledWith(stub.secondCall, config.wallet.host, config.wallet.port, '396e2a782c9ce9993982c6f93e305b05306d0e5794f57157fbac78581443c55f', sinon.match.any, endpoint1, 'DELETE')
              sinon.assert.calledWith(stub.thirdCall, config.wallet.host, config.wallet.port, '{"destinations":[{"amount":11000,"address":"TRTLv2Fyavy8CXG8BPEbNeCHFZ1fuDCYCZ3vW5H5LXN4K2M2MHUpTENip9bbavpHvvPwb4NDkBWrNgURAd5DB38FHXWZyoBh4w"}],"feePerByte":2,"unlock_time":0,"mixin":3}', sinon.match.any, endpoint1)
              sinon.assert.calledWith(stub.call(3), config.wallet.host, config.wallet.port, '{"transactionHash":"396e2a782c9ce9993982c6f93e305b05306d0e5794f57157fbac78581443c55f"}', sinon.match.any, endpoint2)
      })
      })
  </code></pre>
  
  <p>})
  `</p>