1

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?

Chris R
  • 17,546
  • 23
  • 105
  • 172
  • Couldn't this help ? http://stackoverflow.com/questions/1167549/flex-flexunit-how-to-test-that-an-event-is-dispatched-twice – Theo.T Feb 11 '10 at 01:12

1 Answers1

1

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.

Yaba
  • 5,979
  • 8
  • 38
  • 44