[OK]を、これは少し遅れている、と私はこれにかなり長い間を費やしてきたが、私は最終的に仕事にこれを得ています。
私はbeforeEachフックで$ httpBackendを再構築しようとしているとします。私の場合、Appendの設定(またはもっとグローバルなbeforeEachフックで 'backend'という変数に割り当てています。 )、あなたは$ httpBackendサービスにデコレータ機能を追加する必要があります:
app.decorator('$httpBackend', ['$delegate', function ($delegate) {
$delegate.interceptedCalls = [];
var $httpBackend = function (method, url, data, callback, headers, timeout, withCredentials, responseType,
eventHandlers, uploadEventHandlers) {
$delegate.interceptedCalls.push({
method: method,
url: url,
timestamp: new Date(),
type : responseType
});
return $delegate.apply(null, arguments);
};
angular.extend($httpBackend, $delegate);
return $httpBackend;
}]);
ないことすべてがそれを通過するすべての要求のリストが含まれます、あなたのバックエンドオブジェクトにinterceptedCallsプロパティを追加することです。
次に、テストファイルで、次のようなことを行うことができます:
it("forwards the data correctly",function(){
var headers = {
'Content-Type' : 'application/json',
'Accept': 'application/json, text/plain, */*'
};
backend.expectPOST('/someRoute/',{"A" : "B"},headers)
.respond(200,"dsfkjlasdfasdfklsdfd");
service.functionThatCallsSomeRoute({"A" : "B"});
backend.flush();
expect(backend.interceptedCalls[0]['type']).to.equal('arraybuffer');
});
私は本質的にすべてのテストの前にすべてのもの(バックエンドとサービスがテストされている)をリフレッシュしているので、すべてのテストがオブジェクト上で順番に呼び出されます。