Search code examples
actionscript-3flashunit-testingmockingasmock

Simulating as3 dispatch events for unit testing


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!


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..
    }