I'm trying to mock up a promise in some Angular unit tests.
I can't understand why the then()
section below is never firing. Can any one advise?
beforeEach(inject(function ($controller, $rootScope, $q) {
scope = $rootScope.$new();
var mockFactory = {
getData: function() {
var deferred = $q.defer();
deferred.resolve({data: [1,2,3], widget: null});
return deferred.promise;
}
};
mockFactory.getData()
.then(function (response) {
console.log('mockFactory', response);
});
}));
I'm not sure if this issue is related.