我目前正在运行angularjs 1.2.10和使用karma/jasmine with angular-mocks-1.2.10进行单元测试,并停留在$ httpBackend的单元测试用例中。
里面挡住
describe('sumCtrl'...)
...
beforeEach(angular.mock.inject(function($rootScope,$controller,$httpBackend){
scope = $rootScope.$new();
httpBackend = $httpBackend;
$controller('sumCtrl',{$scope:scope});
}));
it("should call these http services",function(){
httpBackend.expectGET('/api/something1/').respond({success:true});
httpBackend.expectPOST('/api/something2/').respond({success:true});
httpBackend.flush();
});
上面的代码完美地工作,但是当我添加一个httpBackend调用
it("should call these http services",function(){
httpBackend.expectGET('/api/something1/').respond({success:true});
httpBackend.expectPOST('/api/something2/').respond({success:true});
httpBackend.expectPOST('/api/something3/').respond({success:true});
httpBackend.flush();
});
这给在线4.不满意请求错误:POST“/ API/something3 '....使用$ httpBackend ....
不知道使用$ httpBackend在其中的请求数量是否有限制或其他需要保留介意使用$ httpBackend。
尝试添加.passThrough()http://docs.angularjs.org/api/ngMockE2E/service/$httpBackend –
但不会直通()调用原始的API。 – icanbeacoder