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?