1
我創建QUnit的測試,以確保我的JSON正確加載和通過AJAX解析到數組,這一切都在瀏覽器工作正常,但是當我通過咕嚕運行它,我得到錯誤:咕嚕沒跑qunit測試與Ajax調用
Running "qunit:files" (qunit) task
Testing test/index.html ...
>> PhantomJS timed out, possibly due to:
>> - QUnit is not loaded correctly.
>> - A missing QUnit start() call.
>> - Or, a misconfiguration of this task.
Warning: 1 tests completed with 1 failed, 0 skipped, and 0 todo.
0 assertions (in 0ms), passed: 0, failed: 0 Use --force to continue.
Aborted due to warnings.
這裏我的測試:
QUnit.test("TSO json loader test", function (assert) {
assert.expect(2);
var done = assert.async();
var done1 = assert.async();
var tsoGrid = new TsoGrid(".testCont");
tsoGrid.loadJsonDataArray("/test/ajax.json", {}, function (jsonResult) {
assert.ok(jsonResult[0][0] === "Lorem ipsum", 'ajaxImportFromJson');
done();
var jsonRes = jsonResult.importFromJsonArray();
var resArray = [["Lorem ipsum"],
["Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante."],
[
[["Lorem ipsum dolor sit amet, consectetuer adipiscing elit."],
["Aliquam tincidunt mauris eu risus.", "Aliquam tincidunt mauris eu risus.1", "Aliquam tincidunt mauris eu risus.2"],
["Vestibulum auctor dapibus neque."]]
]];
assert.ok(jsonRes.isEquals(resArray), 'AjaxImportFromJsonArray');
done1();
});
});
我試圖谷歌這一點,但QUnit移動後異步(),並使用啓動停止()和stop()所有的答案都是過時:(
我發現問題,在這裏的解決方案:
我設置了從我的網站的根查詢的URL,當我刪除它,設置爲文件本身,現在它通過測試從咕嚕!
所以我們需要改變字符串這一點:
tsoGrid.loadJsonDataArray("ajax.json", {}, function (jsonResult) {
從通道中取出/test/
。
爲什麼你'done'和'done1'?你不應該同時需要。 – jakerella
@jakerella Becouse如果我這樣做,我在瀏覽器中得到錯誤:
Too many calls to the 'assert.async' [email protected] 28 ms Source: \t @http://tso/test/test.js:137:9
–什麼?不......你只需要一個......最後一個。 – jakerella