我有一個相當直接的測試,對Angular承諾,我在beforeEach函數中解決,但在我的代碼是不會解僱的,然後我不能看看我錯過了什麼。這些都是用TypeScript編寫的,但這對問題沒有任何影響。茉莉花測試與角落的諾言不解決與TypeScript
這裏是我的測試
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();
});
});
控制器中的刷新方法如下:
refresh() {
this.drillReport({ drillReport: drillReport })
.then((results: Models.drillData) => {
parent.processResults(results, parent.availableDrills, this.columns, this.gridOptions, undefined, undefined);
});
}
謝謝。我知道,但已經忘記了。 –