title: Unit testing with Mocha and Momentjs
body: <p>I have a function that I'm trying to unit test with Mocha that uses <code>moment</code>. </p>
  
  <pre><code>function makeRange(timeagoMinutes) {
    var endDate = moment().toISOString();
    var startDate = moment().subtract(timeagoMinutes, 'm').toISOString();
    return startDate + ',' + endDate;
  }
  </code></pre>
  
  <p>Here is what I have so far, but I'm having trouble figuring out what to do with <code>moment</code>. If I call <code>makeRange(40)</code> and run the tests, the string is different each time.</p>
  
  <p>How can I fake the current time (i.e. <code>moment().toISOString()</code>?</p>
  
  <pre><code>var rewire = require('rewire');
  var controller = rewire('../thecontroller.js');
  var moment = require('moment');
  
  describe.only('makeRange', function() {
    var makeRange;
  
    beforeEach(function() {
      makeRange = controller.__get__('makeRange');
    });
  
    it('should return a string with a start date and end date', function() {
      //
    });
  });
  </code></pre>