I have the following function in my controller:
function putActivities () {
var promises = [];
view.activities.forEach(function (activity) {
promises.push(API.putActivities({activity: activity}).$promise);
});
$q.all(promises).then(function () {
view.finished = true;
});
}
where API is a $resource. This method is tested by the following snippet:
describe('putActivities', function() {
beforeEach(function() {
view.activities = ['hello'];
spyOn(API, 'putActivities').and.callFake(function () {
return {
$promise: q(function () {})
}
});
});
it('view is finished after putting activities', function() {
view.putActivities();
expect(view.finished).toEqual(true);
});
});
For some reason the $q.all never resolves and view.finished
is never set to true. Does anyone know why this may be occurring and how I might fix it?