title: How to mock a Service containing a resource in AngularJS
body: <p>I have a service which contains a resource factory like this:</p>
  
  <pre><code>serviceModule.factory('ProjectResource', ['$resource', function($resource){
      return $resource('/projects/:id.json', {}, {
          'query': {method: 'GET', isArray: true}}
      );
  }]);
  </code></pre>
  
  <p>In a form, which resides in a controller, I inject the serviceModule, and I create a new instance of the resource object: </p>
  
  <pre><code>  $scope.project = new ProjectResource({name: 'Enter a name'})
  </code></pre>
  
  <p>I have some issues with mocking it. I have tried creating a mock object like this, and injecting it in the controller:</p>
  
  <pre><code> mockProjectResource = {
              query: function(){
                  deferred = $q.defer();
                  deferred.resolve({id: 1, :name:'test'});
                  return deferred.promise;
              }
          };
  </code></pre>
  
  <p>No matter the unit test, I get the error:</p>
  
  <pre><code>TypeError: undefined is not a function
  </code></pre>
  
  <p>Which points to the initialization of the Project Resource object (<code>$scope.project = new ProjectResource({name: 'Enter a name'})</code>).</p>
  
  <p>Are there any good way to mock the <code>new ProjectResource(...)</code>?</p>