如何测试 FlexUnit 4 中的事件序列?
我有一个组件,在创建时会分派两个事件来填充数据字段。这些事件应该保持独立,因为它们在其他地方用于不同的操作。
我想编写一个异步 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看序列: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.