My test setups a http request but I do not execute $httpBackend.flush(). Here is the test:
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();
});
});
I expected "$httpBackend.verifyNoOutstandingRequest();" to raise an error hence there was no call to $httpBackend.flush().
I also tried to add "$httpBackend.expectPOST('../api/ModuleApi/GetModules');" but it did not make a difference.