Question

I'm trying to use callLater with FlexUnit v0.9:

public function testCallLater():void {
   Application.application.callLater( addAsync(function():void {
      assertTrue(true);
   }, 1000));
}

but when it runs I get this error:

ArgumentError: Error #1063: Argument count mismatch on flexunit.framework::AsyncTestHelper/handleEvent(). Expected 1, got 0.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]

I'm not sure what the problem is. Is callLater incompatible with FlexUnit?

Was it helpful?

Solution

First, you should really consider migrating to FlexUnit 4.0: http://blogs.digitalprimates.net/codeSlinger/index.cfm/2009/5/3/FlexUnit-4-in-360-seconds

Second, callLater is meant to be used to delay processing until the next frame in visual classes. Your test case class is not a visual class extending UIComponent, therefore you should not try to use callLater.

Third, addAsync is use to test the results of an asynchronous operation. This is typically used in testing the results of a network request, of a file read, of a timer event, etc. That is why normally you see an "event" as a parameter in the addAsync test function (because asynchronous requests use events to process results). In your case, you're not responding to an asynchronous operation with your addAsync call, and therefore you shouldn't be looking for an event in your test function. Remove the event:Event parameter and the error will go away.

However, perhaps you can re-phrase this question to state what you're trying to accomplish? The code sample that you've indicated is not really doing anything useful. If you can be a little more specific we can help you write a better test case.

For help with using addAsync with older versions of FlexUnit, see this tutorial: http://life.neophi.com/danielr/2007/03/asynchronous_testing_with_flex.html

OTHER TIPS

It looks like you are expecting an event, but not getting one. I imagine the following code would work.

public function testCallLater():void {
   Application.application.callLater( addAsync(function(/*removed event declaration*/):void {
      assertTrue(true);
   }, 1000));
}

Just in case someone needs it, this works :

private function testCallLater():void {
    Application.application.callLater(doCallLater, [ addAsync(funcUnderTest, 1000) ]);
}

private function doCallLater(testFunc:Function):void {
    testFunc(null);  // Dummy arg necessary because of addAsync expecting one arg
}

private function funcUnderTest(e:Object = null):void {
    assertTrue(true);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top