gpt4 book ai didi

javascript - 如何在 Javascript 中为服务器的 AjaxCall 编写测试方法?

转载 作者:行者123 更新时间:2023-11-28 02:28:03 26 4
gpt4 key购买 nike

下面给出了有效的ajax调用代码

$('#callControllerBtn').click(function () {
currentlySelectedRow = grid.select();
sendProductIDToController(currentlySelectedRow);
});

function sendProductIDToController(currentlySelectedRow) {
$.ajax({
url: "Home/sendProductID/", // Home = Controller , sendProductID = Action
data: {
ID: pID
},
cache: false,
type: "POST",
timeout: 10000,
dataType: "json",
success: function (result) {
if (result) {
alert("Successfully Completed");
grid.removeRow(currentlySelectedRow);
editor.value("");
} else {
alert("Failed");
}
}
});
}

现在我想编写相同的代码,但使用 JS 测试方法。我在 vs 2010 中使用 QUnit、ChutzPah,让我看看模拟/假 ajax 调用也用测试方法实现工作代码的好做法是什么。

最佳答案

http://net.tutsplus.com/tutorials/javascript-ajax/how-to-test-your-javascript-code-with-qunit/

查看异步章节。

您可以在 $.ajax() 对象文字参数中使用 JQuery 固定属性来指定 ajax 调用应重新路由到的静态文件。 JMVC 文档中对装置有很好的解释:

http://javascriptmvc.com/docs.html#!jQuery.fixture

关于javascript - 如何在 Javascript 中为服务器的 AjaxCall 编写测试方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14588248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com