Pregunta

Cualquiera sabe cómo funciona y si Async.asyncHandler() Async.processOnEvent() sólo se utiliza en el método [Antes]. (Cualquiera sabe algún documento útil, además de http://docs.flexunit.org/ ).

I definir un componente MXML llamado HelloCompo (se extiende Vbox), y el componente de definir un hola llamado función (), en el hello () dispacthed un evento de cliente llamado HelloEvent (el tipo de evento recién nombrado "Hola"), y en otra función init llamado () escuchado durante el evento, quiero poner a prueba si el evento se distribuye correctamente o no. Así que tengo la prueba siguiente:

var helloCompo = nuevo HelloCompo ();

helloCompo.hello();

helloCompo.addEventListener("hello", Async.asyncHandler(this, handleHello, 1000, null, handleTimeOut));

La prueba será siempre excute el método handleTimeOut (mediante la HelloEvent no se distribuye, pero cuando helloCompo.hello () Excute, lo que realmente dispacthed, así que lo que va mal?)

¿Fue útil?

Solución

package flexUnitTests
{
    import flash.events.Event;

    import org.flexunit.asserts.assertTrue;
    import org.flexunit.asserts.fail;
    import org.flexunit.async.Async;

    public class HelloTest
    {       
        private var helloCompo:HelloCompo;

        [Before]
        public function setUp():void
        {
            helloCompo = new HelloCompo();
        }

        [After]
        public function tearDown():void
        {
            helloCompo = null;
        }

        [Test(async)]
        public function testHello():void
        {
            var handler:Function = Async.asyncHandler(this, helloHandler, 300, null, helloFailed);
            helloCompo.addEventListener("hello", handler);
            helloCompo.hello();
        }

        private function helloHandler(event:Event, passThroughObject:Object):void
        {
            //assert somthing
        }

        private function helloFailed(event:Event, passThroughObject:Object):void
        {
            fail("hello not dispatched");
        }


    }
}

HelloCompo.as

package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;

    public class HelloCompo extends EventDispatcher
    {
        public function HelloCompo(target:IEventDispatcher=null)
        {
            super(target);
        }

        public function hello():void
        {
            dispatchEvent(new Event("hello"));
        }
    }
}

Otros consejos

Creo que es necesario agregar el detector de eventos antes de llamar hola () en realidad

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top