如何测试 FlexUnit 4 中的事件序列?

发布于 2024-08-21 19:32:30 字数 841 浏览 5 评论 0原文

我有一个组件,在创建时会分派两个事件来填充数据字段。这些事件应该保持独立,因为它们在其他地方用于不同的操作。

我想编写一个异步 Flexunit 测试来确认这些事件都已发送。问题是,它们都是同一事件的变体。

这是代码:

组件:

internal function creationComplete(): void {
    new GetDataEvent(GetDataEvent.GET_DATA, "aField").dispatch();
    new GetDataEvent(GetDataEvent.GET_DATA, "anotherField").dispatch();
}

测试(据我所知):

[Test(async)]
public function creationCompleteShouldLoadRequiredData(): void {
    Async.handleEvent(this, new CairngormEventDispatcherAdapter(), GetDataEvent.GET_DATA,
            function(event: Event, ...rest): void {
                assertThat(event, hasProperty("data", hasProperty("field", "aField")));
            });
    fixture.creationComplete();
}

问题是,这仅测试第一个获取数据事件是否已调度,更糟糕的是,取决于事件调度的顺序。我如何测试这两个事件最终是否通过此方法发送出去,无论它们的顺序如何?

I have a component that, on creation, dispatches two events to populate data fields. The events should remain separate because they're used elsewhere for distinct actions.

I want to write an asynchronous flexunit test to confirm that these events are both sent. The problem is, they're both variants of the same event.

Here's the code:

Component:

internal function creationComplete(): void {
    new GetDataEvent(GetDataEvent.GET_DATA, "aField").dispatch();
    new GetDataEvent(GetDataEvent.GET_DATA, "anotherField").dispatch();
}

Test (as far as I have it):

[Test(async)]
public function creationCompleteShouldLoadRequiredData(): void {
    Async.handleEvent(this, new CairngormEventDispatcherAdapter(), GetDataEvent.GET_DATA,
            function(event: Event, ...rest): void {
                assertThat(event, hasProperty("data", hasProperty("field", "aField")));
            });
    fixture.creationComplete();
}

The thing is, this only tests that the first get data event is dispatched, and worse, depends on the order of event dispatch. How can I test that both of these events are eventually sent out by this method, regardless of their order?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

如果没有 2024-08-28 19:32:30

查看序列:http://docs.flexunit.org/index.php? title=Sequences#Sequences_from_Fluint

您可以为第一个事件添加一个 SequenceWaiter,并使用最终的 AssertHandler 检查第二个事件。

Check out Sequences: http://docs.flexunit.org/index.php?title=Sequences#Sequences_from_Fluint

You could add a SequenceWaiter for the first event and check the second event with the final AssertHandler.

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