1

I am running FlexUnit tests through Ant. The test test1 fails with the message "Timeout Occurred before expected event" but test2 passes. The only difference between the two tests is that one uses UIImpersonator.addChild() whereas the other uses FlexGlobals.topLevelApplication.addElement().

test1 fails even if I listen for "addedToStage" event. Listening for "added" event, however, makes test1 pass.

[Test(async, ui, description="Fails")]
public function test1():void
{
    var c:UIComponent = new UIComponent;
    Async.proceedOnEvent(this, c, FlexEvent.CREATION_COMPLETE);
    UIImpersonator.addChild(c);
}

[Test(async, ui, description="Passes")]
public function test2():void
{
    var c:UIComponent = new UIComponent;
    Async.proceedOnEvent(this, c, FlexEvent.CREATION_COMPLETE);
    FlexGlobals.topLevelApplication.addElement(c);
}
Ohas
  • 1,887
  • 4
  • 21
  • 29
  • What is UIImpersonator? Does it extend a Flex Application? Or is it a child of a Flex Application? If not; then your 'c' will never go through its Flex LifeCycle process; and the creation_Complete will never be fired. – JeffryHouser Apr 12 '13 at 15:17
  • http://docs.flexunit.org/index.php?title=UIImpersonator I think UIImpersonator may be incompatible with new Flex versions. – Ohas Apr 12 '13 at 15:32
  • Sounds like UIImpersonator should work w/ Spark components: http://forums.adobe.com/thread/905337 – JeffryHouser Apr 12 '13 at 15:35
  • So it *is* a problem with the Flex version. UIImpersonator doesn't seem to behave as expected with newer Flex versions. http://forums.adobe.com/message/5229430#5229430 – Ohas Apr 19 '13 at 13:35

3 Answers3

1

when adding a child, it will not initiate the flex component lifecycle, because displayobject is flash core element, not flex.

csomakk
  • 5,369
  • 1
  • 29
  • 34
  • This answer is equally confusing. When adding a child [to what]; [what] will not initiate the Flex Component Component LifeCycle because DisplayObject is a Flash Core element. I think the 'what' in this case may be the UIImpersonator instance; however according to these docs: http://docs.flexunit.org/index.php?title=UIImpersonator it sounds like UIImpersonator will mimic the Flex Component LifeCycle and it explicitly calls out that the creation_Complete event should fire. I'd feel bad for downvoting again; so I won't. – JeffryHouser Apr 12 '13 at 15:32
  • I think the point is that UIImpersonator fakes Flex Lifecycle events (I was at a presentation once where you isted them, so I won't bore you with what they are), _not_ Display Object events. – Amy Blankenship Apr 12 '13 at 17:59
0

assuming Flex4/spark. addChild adds a MovieClip, not a Flex UIElement, it doesn't even know FlexEvent type as it is a flash.core object. It will only throw addedToStage or added events (Event.added), but in unit test, it is not added to stage, because UIImpersonator is not part of the stage

csomakk
  • 5,369
  • 1
  • 29
  • 34
  • This is wrong. The argument of addChild is a DisplayObject, not a MovieClip ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#addChild() ). DisplayObject is in the Flex UIComponent hierarchy: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/UIComponent.html so a Flex UIComponent is a DisplayObject and can be used with AddChild() without problems--in fact; addElement is just a wrapper around addChild that was added in the Flex 4 Spark component architecture. – JeffryHouser Apr 12 '13 at 15:20
  • uielement extends uicomponent, that does not mean uicomponent will know uielement, but uielement will know uicomponent. – csomakk Apr 12 '13 at 15:22
  • i see your pont. raised a new answer – csomakk Apr 12 '13 at 15:25
  • I don't know what UIElement is; nor how it relates here. Your edits improve this answer, but it is still not enough for me to remove my downvote. Recommended changes: Clarify that addChild() adds a DisplayObject. And the UIComponent will only throw addedToStage or added events needs to be revised, as it is inaccurate. You're new answer is equally confusing. – JeffryHouser Apr 12 '13 at 15:28
0

I ran into this same issue today using the new Apache FlexUnit 4.2.0 release.

When trying to run the sampleCIProject included in the binary distribution, none of the tests that used Async would succeed. The exception was exactly as described above.

After looking at the source code for a while, I noticed that the core FlexUnit libraries have two flavours: flexunit-4.2.0-20140410-as3_4.12.0.swc and flexunit-4.2.0-20140410-flex_4.12.0.swc.

The first of these is intended for pure AS3 projects, while the latter is intended for projects that use Flex. The sampleCIProject included both of these libraries in the library path, and I'm assuming that it was using the UIImpersonator class from the pure AS3 library rather than the Flex-supporting one. I removed flexunit-4.2.0-20140410-as3_4.12.0.swc from the project, and lo and behold, the Async tests started working again.

Probably a bit late for you, but I hope this helps someone else.

ajkerr
  • 456
  • 5
  • 2