1
我试图在Qunit中获得一系列测试工作。我正在与JQM合作,并使用他们的测试套件,其中包括一个$.mobile.testHelper
对象,我正在为其添加方法。为什么Qunit不能捕捉我正在运行的2+测试?
这里是我的代码(意见和日志):
// my test page is loaded inside an iframe
var frame = document.getElementsByTagName("iframe")[0];
var d = frame.contentDocument;
var w = frame.contentWindow;
var $i = w.$(d);
var $body = w.$("body");
// forcing $(body) as event target
$.testHelper.eventTarget = $body;
// sets "one" listener on "step" event and jumps to next method when triggered
$.testHelper.stepSequence = function (fns) {
$.testHelper.eventSequence("step", fns);
};
// run a test
$.testHelper.runTest = function (command, condition) {
console.log("RUNNING TEST...");
ok(condition, command);
};
// try 10x if a condition is met, wait 1000ms in between
$.testHelper.countDown = function (arr, command) {
var condition, is_done;
var ticker = 0;
var i = w.setInterval(function() {
switch (command) {
case "verifyAttribute":
condition = $i.find(arr[0]).eq(0).attr(arr[1]).indexOf(arr[2]) > -1;
break;
case "waitForElementPresent":
condition = $i.find(arr[0]).length > 0;
break;
}
if (condition) {
console.log("CONDITION PASSED, RUN TEST");
$.testHelper.runTest(command, condition);
w.clearInterval(i);
}
ticker += 1;
console.log(ticker);
if (ticker === 10) {
console.log("FAILED, RUN WITH undefined to fail test");
$.testHelper.runTest(command, condition);
w.clearInterval(i);
}
}, 1000);
};
// my test module
module("UI Basic Interaction");
asyncTest("${base_url}", function() {
expect(2);
// here is my sequence of methods
$.testHelper.stepSequence([
function() {
w.setTimeout(function() {
$body.trigger("step");
}, 800);
$.testHelper.countDown(["div#global-panel", undefined, undefined], "waitForElementPresent");
},
function() {
w.setTimeout(function() {
$body.trigger("step");
}, 800);
$("a:contains('Menu')").trigger("click");
},
function() {
w.setTimeout(function() {
$body.trigger("step");
}, 800);
$.testHelper.countDown(["div#global-panel", "class", "ui-panel-open"], "verifyAttribute");
},
function() {
w.setTimeout(function() {
$body.trigger("step");
}, 800);
$("h1:contains('My Account')").trigger("click");
},
function() {
start();
}
])
});
我需要触发“台阶”的试验条件下运行后,却无法得到它的工作,所以我使用的没有不错setTimeout
我的问题是,第一次测试通过,第二次测试正确开始间隔,而UI呈现,但是当元素被发现时,几乎同时出现了Expected 2 assertions, but 1 were run
错误我的控制台报告情况为真。
问:
从上面的代码,有没有在我的测试程序的错误,不运行runTest
“快”不够,因为Qunit出错了呢?此外,我会很高兴为更好的方式来触发"step"
。
谢谢!
我对JQM'testhelper'不熟悉,但它看起来像'countDown'函数可能会等待10秒,但'QUnit.start'将在大约4x800ms后运行。 – psquared
真的,现在玩的时机。 – frequent
@psquared:有帮助,请参阅下面的答案 – frequent