私は現在 angularjs 1.2.10 を実行しており、単体テストのために 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();
});
上記のコードは完全に機能しますが、もう 1 つ 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 行目でエラーが発生します。 Unsatisfied Request: POST '/api/something3' .... use $httpBackend....
ブロック内で $httpBackend を使用して行われるリクエストの数に制限があるのか 、それとも $httpBackend を使用する際に留意する必要がある何かがあるのか わかりません。