你需要做asyncTest
一个简单的test
调用。这是我使用的一个示例:
...
asyncTest("test title", function() {
$.mockjaxClear(); // clear any existing mock jax entries (could be in a setup method)
$.mockjax({ // pass in your request matcher / response object
url: '/some/file.php',
type: 'post',
status: 200,
dataType: 'json',
response: function(req) {
this.responseText = JSON.stringify({some: "data"});
}
});
$.ajax({
url: '/some/file.php',
type: 'post',
dataType: 'json',
success: function(d) {
a.deepEqual(d, {some: "data"}, "Object data is correct in callback");
// other tests
start(); // this tells QUnit to start back up, async is done
});
...
});
以及QUnit 中 Async 控制的一些文档。