title: TypeError: 'undefined' is not a function (evaluating 'moment()')
body: <p>I'm setting a date value using moments.js in my controller. I'm getting following error when running trying to run a spec against it: </p>
  
  <p>TypeError: 'undefined' is not a function (evaluating 'moment()')</p>
  
  <p>I don't care about testing that the value is set correctly, I just want the date value to be defined to allow the test to proceed. What's the best way to mock this? I've tried using jasmine.clock() as suggested in related questions, but the test is still trying to evaluate moment(). Ideally I would be able to just set controller.date to some arbitrary value for test purposes before each test.</p>
  
  <p>Here's the code in my controller (set date is called on controller initialization):</p>
  
  <pre><code>function setDate() {
    controller.date = {
        startDate: moment().subtract(1, "days").hour(0).minute(0).second(0),
        endDate: moment()
    };
  }
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>Here's the relevant controller code:</p>
  
  <pre><code>.controller('OrderListCtrl', function ($rootScope, $state, $stateParams, $uibModal, $q, orders, Orders, Product, Store, Payments, params) {
  
          var controller = this;
  
          // set default values for datepicker - beginning of yesterday until current time today
          controller.setDate = function() {
            controller.date = {
                startDate: moment().subtract(1, "days").hour(0).minute(0).second(0),
                endDate: moment()
            };
          }
  
          controller.setDate();
      });
  </code></pre>
  
  <p>Here's the relevant spec code:</p>
  
  <pre><code>describe("OrderController", function() {
  
      var orderController, deferred, params, scope, state, stateParams, uibModal, q, controller, moment;
  
      beforeEach(inject(function ($controller, $rootScope, $q, $uibModal) {
          scope = $rootScope.$new();
          q = $q;
          controller = $controller;
          uibModal = $uibModal;
  
          deferred = $q.defer();
  
          orderController = controller('OrderListCtrl', {
              $rootScope: scope,
              $state: state,
              $stateParams: stateParams,
              $uibModal: uibModal,
              $q: q
          });
  
          orderController.setDate = function() {
            orderController.date = {
              startDate: new Date('01/01/2016'),
              endDate: new Date('01/02/2016')
            }
          }
  
      }));
  </code></pre>
  
  <p>Trying to override the setDate() method in this way apparently isn't working, it's still throwing an error: "can't find moment variable".</p>