Question

I'm writing some unit test and would like to test how my components are reacting to some specific flash events. So I need a way to dispatch those events. I think that that's possible.

I'm trying to use asmock but trying to piece together info from http://asmock.sourceforge.net/wiki/Quick_Start_Guide is failing me.

If someone could point me to a complete example, that would be great! Also open to use other testing frameworks.

Thanks!

Was it helpful?

Solution

Hm, how about that:

public class  EventSimulator extends EventDispatcher
{
    public function doMouseClick():void {
        dispatchEvent(new MouseEvent(MouseEvent.CLICK));
    }

    public function doChange():void {
        dispatchEvent(new Event(Event.CHANGE));
    }
    //and so on..
}

OTHER TIPS

If you're already using asMock, then you can do this:

var dispatcher2 : IEventDispatcher = 
 IEventDispatcher(mockRepository.createStub(IEventDispatcher, StubOptions.NONE));
mockRepository.stubEvents(dispatcher2);

// Call mockRepository.dispatchEvent() or .addEventListener() as normal

However, if you're not, then asMock would be overkill as per ZuzEL's answer.

(Disclaimer: I'm the author of asMock, and that documentation)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top