title: Sinon Spies -- Testing a recursive (and possibly const) function expression
body: <p>I am using Mocha with Sinon and attempting to test a recursive call (fibonacci). My code is:</p>
  
  <pre><code>'use strict';
  
  let sinon = require('sinon'),
      chai = require('chai'),
      expect = chai.expect;
  
  chai.use(require('sinon-chai'));
  
  let fib = function (n) {
      if (n === 0) {
          return 0;
      } else if (n === 1) {
          return 1;
      } else {
          return fib(n-2) + fib(n-1);
      }
  };
  
  describe('fib', function() {
          it('should repeat calculations', function() {
              let originalFib = fib;
              fib = sinon.spy(fib)
  
              expect(fib(6)).to.equal(8);
              expect(fib).to.have.callCount(25);
  
              fib = originalFib;
          });
  });
  </code></pre>
  
  <p>This code works as-is, however, if I replace the line:</p>
  
  <pre><code>let fib = function (n) {
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>const fib = function (n) {
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p><em>TypeError: Assignment to constant variable.</em></p>
  
  <p>This is as expected, but it raises the question, how would I test a recursive function that was declared const using Sinon?</p>
  
  <p><strong>Edited</strong> Jasmine has something called .callThrough() which seems to allow testing of recursive function.</p>
  
  <p>It seems to me there is no way to replicate this behavior with Sinon? I have  looked at the following bug reports / feature requests:</p>
  
  <p><a href="https://github.com/sinonjs/sinon/issues/668" rel="nofollow noreferrer">https://github.com/sinonjs/sinon/issues/668</a></p>
  
  <p><a href="https://github.com/sinonjs/sinon/issues/989" rel="nofollow noreferrer">https://github.com/sinonjs/sinon/issues/989</a></p>
  
  <p>Thank you.</p>