title: How to create a unit test for a function that uses $filter 'date'
body: <p>I am writing a unit test for a function within my controller.</p>
  
  <p>The function uses the $filter to format the date in 'yyyy-MM-dd' format.</p>
  
  <p>However my karma script fails to run after the line on which the filter is used.</p>
  
  <p><strong>Here's the function:</strong></p>
  
  <pre><code>$scope.myFunction = function (someDate) {
  
      var dateTo = new Date(someDate);
      var myDate = $scope.myDate;
  
      // Code fails after line below on unit test /////
      var searchdate = (filter('date')(myDate, 'yyyy-MM-dd'));
      searchdate = serviceConvertISODate.convertDate(searchdate);        
  }
  </code></pre>
  
  <p>In the example above, var myDate = 1405967947000 (epoc format)</p>
  
  <p><strong>Unit test:</strong></p>
  
  <pre><code>describe('Validating functions within Controller', function () {        
  
      var scope, ctrl, filter, localServiceConvertISODate;
  
      beforeEach(inject(function($controller, $rootScope, $filter, serviceConvertISODate) {
          scope = $rootScope.$new(),
          ctrl = $controller('MyController', {
              $scope: scope,
              filter : $filter,
              serviceConvertISODate : localServiceConvertISODate
          });                
      }));
  
      it('should test my function', function() {
  
          var dateTo = new Date("22 Sep 2014");
          console.log("********* dateTo = " + dateTo );
  
          var myDate = $scope.myDate;
          console.log("********* myDate = " + myDate );
  
          var searchdate = (filter('date')(myDate, 'yyyy-MM-dd'));
          console.log("searchdate after filter = " + searchdate);
  
          searchdate = localServiceConvertISODate.convertDate(searchdate);            
  
      });
  });
  </code></pre>
  
  <p>I can see through my logs:</p>
  
  <pre><code>dateTo is returning the correct new date
  
  myDate is returning the correct myDate
  </code></pre>
  
  <p>However, applying the next line (filter), causes the test to break and no error is provided.</p>