I have a fairly straightforward test that works against an Angular promise, which I'm resolving in the beforeEach function, but the then in my code is not ever firing and I can't see what I'm missing. These are written with TypeScript, but that doesn't really have any bearing on the problem.
Here is my test
describe('Refresh->', () => {
var controller = new Directives.Reporting.ReportDirectiveController($scope, $q, $location);
var called = false;
var defer: any;
beforeEach((done) => {
controller.drillReport = (drillReport: Models.drillReport): ng.IPromise<Models.drillData> => {
defer = $q.defer();
called = true;
defer.resolve({});
return defer.promise;
};
spyOn(controller, 'processResults');
controller.refresh();
done();
});
it('Calls DrillReport', () => {
expect(called).toBeTruthy();
});
it('Calls ProcessResults', () => {
expect(controller.processResults).toHaveBeenCalled();
});
});
The Refresh method in the controller looks like this:
refresh() {
this.drillReport({ drillReport: drillReport })
.then((results: Models.drillData) => {
parent.processResults(results, parent.availableDrills, this.columns, this.gridOptions, undefined, undefined);
});
}