【发布时间】:2011-01-11 16:35:02
【问题描述】:
我正在尝试在 jasmine 中加载数据集以进行此类测试... 然而,由于它是一个 json 调用,我似乎无法总是得到由“it”表示的测试,以等待 JSON 调用完成后再使用它的数组。我尝试使用 ajaxStop 函数无济于事。有什么想法吗?
describe("simple checks", function() {
var exampleArray = new Array();
beforeEach(function(){
$(document).ajaxStop(function() {
$(this).unbind("ajaxStop");
$.getJSON('/jasmine/obj.json', function(data) {
$.each( json.jsonattr, function(i, widgetElement) {
exampleArray.push(new widget(widgetElement));
});
});
});
});
it("use the exampleArray", function() {
doSomething(exampleArray[0]); // frequently this is coming up as undefined
});
【问题讨论】:
标签: jquery unit-testing json synchronous jasmine