0

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!

m.y
  • 691
  • 9
  • 21

2 Answers2

0

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..
}
ZuzEL
  • 12,768
  • 8
  • 47
  • 68
0

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)

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
  • Hello Richard, your reputation does precede you ;) Thanks for that. I might require a mocking framework indeed. So you might hear more from me :) – m.y Jul 11 '13 at 16:56