質問

誰もがどうやってやるのか知っています Async.asyncHandler() 仕事と場合 Async.processOnEvent() 前]メソッドでのみ使用できます。(誰もがいくつかの役立つ文書を知っています http://docs.flexunit.org/).

HelloCompo(extends Vbox)という名前のMXMLコンポーネントを定義し、コンポーネントはHello()という名前の関数を定義します。 init()イベントを聞いたところ、イベントが適切に発送されているかどうかをテストしたいと思います。だから私はテストを持っています:

var hellocompo = new HelloCompo();

helloCompo.hello();

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

このテストは常にHandletimeoutメソッドをエクスパートします(HelloEventが派遣されていないことを意味しますが、Hellocompo.hello()Excuteが実際に派遣されたとき、何が悪いのですか?)

役に立ちましたか?

解決

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

他のヒント

実際にhello()を呼び出す前に、イベントリスナーを追加する必要があると思います

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top