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