flexunit addAsync 链接
由于某种原因,Flexunit 测试中的 addAsync 链接如 这篇文章 当我尝试这样做时完全失败。
public function testWhatever():void {
var cont:EventDispatcher = new EventDispatcher();
cont.addEventListener("continue", addAsync(verifyFirst, 1000));
cont.dispatchEvent(new Event("continue"));
}
private function verifyFirst(e:Event):void {
var cont:EventDispatcher = new EventDispatcher();
cont.addEventListener("continue", addAsync(verifySecond, 1000));
cont.dispatchEvent(new Event("continue"));
}
private function verifySecond(e:Event):void {
assertTrue(true);
}
如果我运行此测试,verifyFirst 会被调用,但 verifySecond 不会。 我假设这是 flexunit 中的一个错误......有解决方法吗?
For some reason, addAsync chaining in a flexunit test as described in this article utterly fails to work when I try to do it.
public function testWhatever():void {
var cont:EventDispatcher = new EventDispatcher();
cont.addEventListener("continue", addAsync(verifyFirst, 1000));
cont.dispatchEvent(new Event("continue"));
}
private function verifyFirst(e:Event):void {
var cont:EventDispatcher = new EventDispatcher();
cont.addEventListener("continue", addAsync(verifySecond, 1000));
cont.dispatchEvent(new Event("continue"));
}
private function verifySecond(e:Event):void {
assertTrue(true);
}
If I run this test, verifyFirst gets called but verifySecond does not. I'm assuming this is a bug in flexunit ... is there a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一些更多的研究,发现这确实是 flexunit 中的一个错误,看起来是 在下一版本中修复。 我发现的解决方法是使用
Application.application.callLater
来调度第二个事件。这个问题的灵感来自于在处理 Flash 事件队列中的所有内容后尝试检查对象的状态。 我发现了一种更简单的方法来完成此任务,而无需弄乱
EventDispatcher
。当您希望处理事件队列时,请在测试第一部分结束时进行以下调用。
Application.application.callLater(addAsync(phaseTwo, 1000, [
args...]), [null]);
使用
>phaseTwo
函数具有以下签名。private function PhaseTwo(e:Event, args:Array):void
e
将传递一个null
对象。 这是与addAsync
兼容所必需的。I did some more research and found that this is indeed a bug in flexunit, which looks to be fixed in the next release. The workaround I found was to instead use
Application.application.callLater
to dispatch the second event.This question was inspired by an attempt to inspect the state of an object after everything in Flash's event queue had been processed. I discovered a simpler way to accomplish this without messing with
EventDispatcher
s.Make the following call the end of the first part of the test when you want the event queue to be processed.
Application.application.callLater(addAsync(phaseTwo, 1000, [
args...]), [null]);
With the
phaseTwo
function having the following signature.private function phaseTwo(e:Event, args:Array):void
e
will be passed anull
object. This is necessary to be compatible withaddAsync
.