我的测试设置了一个 http 请求,但我没有执行 $httpBackend.flush()。这是测试:
describe("Unit: Testing Services", function() {
beforeEach(angular.mock.module('EmsWeb.Services'));
describe("Unit: DalService", function () {
var $httpBackend, dalService, appModel;
beforeEach(inject(function ($q, _$httpBackend_, AppModel, DalService) {
dalService = DalService;
appModel = AppModel;
$httpBackend = _$httpBackend_;
$httpBackend.when('POST', '../api/ModuleApi/GetModules').respond({ userId: 'userX', 'A-Token': 'xxx' });
appModel.context.company = { code: 'LPL' };
}));
describe("canceling request should fail", function () {
it('checks request should be canceled ', function () {
// $httpBackend.expectPOST('../api/ModuleApi/GetModules');
var returnedData;
var callBackFn = function (data) {
returnedData = data;
};
dalService.getModules('senderIdentifier', appModel.context, callBackFn, callBackFn);
});
});
afterEach(function () {
$httpBackend.verifyNoOutstandingRequest();
});
});
我预计$httpBackend.verifyNoOutstandingRequest();
会引发错误,因此没有调用$httpBackend.flush()
.
我也尝试添加$httpBackend.expectPOST('../api/ModuleApi/GetModules');
,但没有任何区别。
我错过了什么?