Some help with testing dispatched events

jiri's Avatar

jiri

13 Aug, 2010 03:29 PM

I am testing a model that I use in a RL setup, the model dispatches events. I want to test somehow that the right event is being dispatched when I call a method. I use ASunit and because I am really new to unit testing I can't really find out how to verify a certain event and event.type is dispatched as expected.

package {

    public class TreatmentProgressDisplayModelTest
    {
        [Before]
        public function init():void {
            _model = new TreatmentProgressDisplayModel();
            _model.eventDispatcher = new DummyEventDispatcher(_model);
        }
        [Test]
        public function testCurrentTreatmentAvailable():void {
            _model.dispatch_a_certain_event_here.
                       //how to test now that the expected event is dispatched??
        }

...
//internal class
import flash.events.Event;
import flash.events.EventDispatcher;

import net.wooga.pets.models.TreatmentProgressDisplayModel;

class DummyEventDispatcher extends EventDispatcher
{
    private var _model:TreatmentProgressDisplayModel;
    
    public function DummyEventDispatcher(model:TreatmentProgressDisplayModel):void
    {
        _model = model;
    }
    
    override public function dispatchEvent(event : Event):Boolean
    {
        return true;
    }
}

  1. Stray closed this discussion on 10 Feb, 2011 05:35 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac