我创建了QUnit测试以确保我的JSON通过AJAX正确加载并解析为数组,它在浏览器中运行良好,但是当我通过Grunt运行时我得到错误:
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转移到async()并停止使用start()和stop()后,所有答案都已过时:(
我发现问题,此处为解决方案:
我从我的网站的根目录设置了查询的URL,当我删除它时,设置为文件本身,现在它从grunt传递测试!
所以我们需要改变字符串:
tsoGrid.loadJsonDataArray("ajax.json", {}, function (jsonResult) {
从路径中移除/test/
。
答案 0 :(得分:0)
我发现问题,这里有解决方案:
我从我网站的根目录设置了查询网址,但它必须是本地路径!
所以你需要改变本地文件的路径,我的情况是它存储在与测试文件相同的文件夹中。
这是工作测试:
QUnit.test("TSO json loader test", function (assert) {
assert.expect(2);
var done = assert.async();
var tsoGrid = new TsoGrid(".testCont");
tsoGrid.loadJsonDataArray("ajax.json", {}, function (jsonResult) {
assert.ok(jsonResult[0][0] === "Lorem ipsum", 'ajaxImportFromJson');
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');
done();
});
});