Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/evan-liu/as3-signals-utilities-async

Async test support for as3-signals
https://github.com/evan-liu/as3-signals-utilities-async

Last synced: 3 months ago
JSON representation

Async test support for as3-signals

Awesome Lists containing this project

README

        

h2. Utility classes for unit test signals.

This library is a utility for "Robert Penner":http://robertpenner.com/ 's "as3-signals":http://github.com/robertpenner/as3-signals with some delegate methods to test them with FlexUnit4:

* proceedOnSignal
* handleSignal
* failOnSignal
* registerFailureSignal

h3. proceedOnSignal

Use this method to ensure that some signal is dispatched during an asynchronous test.


[Test(async)]
public function test_proceedOnSignal():void
{
var model:IModel = new SomeModel();
proceedOnSignal(this, model.changedSignal);
model.doSomethingChange();
}

h3. handleSignal

Use this method to ensure that some signal is dispatched and do more assertions in the handler. The handler method must have two arguments. The first one is a SignalAsyncEvent, you can get all arguments passed by the signal's dispatch() method by event.args. The second Object typed argument is the data passed by the passThroughData argument in the handleSignal method.


[Test(async)]
public function change_user():void
{
var model:IModel = new SomeModel();
handleSignal(this, model.changedSignal, verify_user, 500, {name:"Tom", age:20});
model.changeUser("Tom", 20);
}
private function verify_user(event:SignalAsyncEvent, data:Object):void
{
assertEquals(event.args[ 0 ], data.name);
assertEquals(event.args[ 1 ], data.age);
}

h3. failOnSignal

Use this method to ensure that some signal is not dispatched during an asynchronous test in a time period.


[Test(async)]
public function not_changed():void
{
var model:IModel = new SomeModel();
failOnSignal(model.changedSignal);
model.doSomethingNotChange();
}

h3. registerFailureSignal

Use this method to fail a test when a signal is dispatched. Think you are waiting for a success signal of a service, you will want to fail the test when the service's error signal is dispatched instead of waiting until timeout.


[Test(async)]
public function call_service():void
{
var service:IService = new SomeService();
registerFailureSignal(this, service.failedSignal);
proceedOnSignal(this, service.successSignal);
service.call();
}