0
我有一個關於嘲笑茉莉花xhr的問題。我有以下的Javascript情況:嘲笑xhr呼叫茉莉花
function Test1(){
// some code
Test2({ readyState: 4, responseText: "", status: 200, statusText: "OK" });
}
function Test2(xhr){
var token = xhr.getResponseHeader("csrftoken");
var csrfCtrl = $("#token");
if (token != null && csrfCtrl != null) {
csrfCtrl.val(token);
}
}
現在我想spyOn的xhr.getResponseHeader()
功能,但我無法找到我怎麼能做到這一點。
我想是這樣的:
describe("1 || Test ||", function() {
// Before we describe the tests we first need to setup a few things
beforeEach(function() {
// Load the first function of the HTML fixtures (htmlfixtures.js)
setUpHTMLFixture1();
jQuery.xhr = spyOn(jQuery.fn.ajax.xhr, "getResponseHeader").and.returnValue("null");
});
it("1.1 # Check xhr functionality", function() {
expect(jQuery.xhr).toHaveBeenCalled();
});
});
但沒有奏效。有任何想法嗎?也許重要的是要注意。我使用jQuery 1.8。
謝謝!這會幫助我很多! :) – Rotan075