我正在使用Jasmine和Sinon来测试ajax调用。测试看起来像这样:
describe("function initialize", function(){
var server;
beforeEach(function(){
server = sinon.fakeServer.create();
});
afterEach(function() {
server.restore();
});
it ("should make an ajax call successfully", function(){
server.respondWith(session.apipath + "/login/refreshToken/",
[200, { 'Content-Type': 'application/json' },
'{user:"asdf",loginToken:"bla"}']);
session.initialize();
server.respond();
expect(localStorage.getItem("loginToken")).toBe("bla");
});
});
我想让它调用成功函数。
$.ajax(this.apipath + "/login/refreshToken/", {
success: function (response) {
alert("success!!!");
localStorage.setItem("loginToken", response.loginToken);
},
error: function(){
alert("error!!!");
}
});
但只调用错误。我做错了什么?