Skip to content

Instantly share code, notes, and snippets.

@drewbourne
Created August 8, 2011 23:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewbourne/1133025 to your computer and use it in GitHub Desktop.
Save drewbourne/1133025 to your computer and use it in GitHub Desktop.
Dispatching Events with Mockolate Mocks
package mockolate.example
{
import flash.events.Event;
import mockolate.mock;
import mockolate.runner.MockolateRule;
import org.flexunit.assertThat;
import org.hamcrest.object.isFalse;
import org.hamcrest.object.isTrue;
public class DispatchingEvents
{
[Rule]
public var mocks:MockolateRule = new MockolateRule();
[Mock]
public var injected:InjectedClass;
public var target:TargetClass;
[Before]
public function setup():void
{
mock(injected).asEventDispatcher();
target = new TargetClass();
target.injected = injected;
}
[Test]
public function afterInjectedIsComplete_targetWasEventFired_shouldBeTrue():void
{
assertThat("before injected is complete wasEventFired should be false",
target.wasEventFired, isFalse());
injected.dispatchEvent(new Event(Event.COMPLETE));
assertThat("after injected is complete wasEventFired should be true",
target.wasEventFired, isTrue());
}
}
}
package mockolate.example
{
import flash.events.EventDispatcher;
[Event(name="complete", type="flash.events.Event")]
public class InjectedClass extends EventDispatcher
{
}
}
package mockolate.example
{
import flash.events.Event;
public class TargetClass
{
private var _injected:InjectedClass;
private var _wasEventFired:Boolean;
public function set injected(value:InjectedClass):void
{
_injected = value;
_injected.addEventListener(Event.COMPLETE, injected_complete);
}
private function injected_complete(event:Event):void
{
_wasEventFired = true;
}
public function get wasEventFired():Boolean
{
return _wasEventFired;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment