I'm testing my directive which used Restangular for some API calls in the controller.
For functions with promises used by Restangular I'm mocking those functions and putting together with my main model, which looks like this:
model = {
comments: comments,
one: function () {
deferred = $q.defer();
return deferred.promise;
},
post: function () {
deferred = $q.defer();
return deferred.promise;
},
remove: function () {
deferred = $q.defer();
return deferred.promise;
}
};
And so when executing a function which runs Restangular's function e.g.:
$scope.model.post('comments', newComment).then(...);
Me myself deciding to reject or to resolve it:
deferred.reject();
$scope.$digest();
Everything works fine but not when the functions are nested, for example like here:
$scope.model.one('comments', comment.id).remove().then(...);
In this case I'm getting an error that remove is not defined (though I defined it):
TypeError: 'undefined' is not a function (evaluating '$scope.model.one('comments', comment.id).remove()')
Am I missing something?