views:

155

answers:

2

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?

+1  A: 

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
A: 

try this

ktutnik
But that's not Flex Unit 4. EventfulTestCase is no longer part of it.
Yaba