【发布时间】:2011-11-18 14:37:08
【问题描述】:
我有 jQuery 代码,当我点击一个链接时,它首先隐藏然后删除一些 HTML,如下所示:
$(this).parent().parent().hide('slow', function () {
$(this).remove();
});
我想进行 QUnit 测试,确保相关 HTML 已被删除:
$(thelink).click();
// Check that it is gone, by finding the first item in the list
entity = input.form.find('.recurrenceinput_occurrences .occurrence span.action a')[0];
// And make sure it's NOT the deleted one:
ok(entity.attributes.date.value !== "20110413T000000");
问题当然是 ok() 测试是在 hide 动画运行结束之前运行的,所以有问题的 HTML 还没有被删除,测试失败了。
我尝试了各种方法来延迟/停止测试一秒钟左右,但似乎没有任何效果。最明显的一个是使用 asynTest 并做
stop();
setTimeout(start, 2000);
但这实际上并没有停止测试。它似乎确实停止了 某事 两秒钟,但我不确定是什么。 :-)
有什么想法吗?
【问题讨论】:
标签: javascript jquery qunit