flexunit addAsync 链接

发布于 2024-07-10 05:48:25 字数 838 浏览 6 评论 0原文

由于某种原因,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-07-17 05:48:25

我做了一些更多的研究,发现这确实是 flexunit 中的一个错误,看起来是 在下一版本中修复。 我发现的解决方法是使用 Application.application.callLater 来调度第二个事件。

private function verifyFirst(e:Event):void {
    var cont:EventDispatcher = new EventDispatcher();
    cont.addEventListener("continue", addAsync(verifySecond, 1000));
    Application.application.callLater(cont.dispatchEvent,
       [new Event("continue")]);
}

这个问题的灵感来自于在处理 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.

private function verifyFirst(e:Event):void {
    var cont:EventDispatcher = new EventDispatcher();
    cont.addEventListener("continue", addAsync(verifySecond, 1000));
    Application.application.callLater(cont.dispatchEvent,
       [new Event("continue")]);
}

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 EventDispatchers.

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 a null object. This is necessary to be compatible with addAsync.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文