Currently, I am in the process of writing unit tests for a project built with Angular version 1.2.
For my controller tests, I have set up a mockService that returns a deferred promise. One of the service methods looks like this:
function getItems() {
var deferred = $q.defer();
deferred.resolve(["item1", "item2"]);
$rootScope.$apply();
return deferred.promise;
}
However, when I invoke this service method and trigger the deferred.resolve function, an error occurs:
TypeError: 'undefined' is not an object (evaluating 'promise.data.map')
I am unsure what promise.data.map
refers to and how to resolve this error. Can anyone provide insights on fixing this issue?