flexunit of handle customer event和Async.asyncHandler()

jas*_*son 3 apache-flex flexunit flexunit4

任何人都知道怎么做 Async.asyncHandler()工作,如果Async.processOnEvent()只能在[Before]方法中使用.(除了http://docs.flexunit.org/之外,任何人都知道一些有用的文件).

我定义了一个名为HelloCompo(扩展Vbox)的MXML组件,该组件定义了一个名为hello()的函数,在hello()中发生了一个名为HelloEvent的客户事件(事件类型名为"hello"),并在另一个函数中命名init()监听事件,我想测试事件是否正确调度.所以我有以下测试:

var helloCompo = new HelloCompo();

helloCompo.hello();

helloCompo.addEventListener("hello", Async.asyncHandler(this, handleHello, 1000, null, handleTimeOut));
Run Code Online (Sandbox Code Playgroud)

测试将始终执行handleTimeOut方法(意味着不调度HelloEvent,但是当helloCompo.hello()执行时,它确实发生了干扰,所以出了什么问题?)

Flo*_*n F 6

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");
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

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"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)