我有以下代码:
window.onload= function() {
var requestData = {
bookId:$('.bookId').text()
};
if(window.location.href.indexOf("/viewbook")!=-1){
$.post("check-book", requestData, function (response) {
if(response == "already saved") {
$('.add-btn').attr('disabled', 'disabled');
}
});
}
};
我正在尝试在 Jasmine 中编写一个适当的测试。所以,到目前为止,我有以下代码:
describe("should disable button", function () {
it("should check if book exists in list while loading page", function () {
var localContext = {
"window":{
location:{
href:"/viewbook"
}
}
}
with(localContext){
spyOn($, 'post');
window.load();
expect(window.location.href).toBe("/viewbook");
//expect($.post).toHaveBeenCalled();
}
});
});
但是当我运行它时,它给了我一个错误,即对象的负载未知。你知道如何测试吗?
谢谢