mockolate icon indicating copy to clipboard operation
mockolate copied to clipboard

Mocking and stubbing FileReference.data fails in Flex project

Open luddet opened this issue 13 years ago • 0 comments

The code below works in a Flex Library Project but fails in a Flex Project.

package flexUnitTests
{
    import flash.net.FileReference;
    import flash.utils.ByteArray;

    import mockolate.runner.MockolateRunner;
    import mockolate.stub;

    import org.flexunit.assertThat;
    import org.flexunit.asserts.fail;
    import org.hamcrest.object.equalTo;
    import org.hamcrest.object.instanceOf;
    import org.hamcrest.object.notNullValue;
    import org.hamcrest.object.sameInstance;

    MockolateRunner;

    [RunWith("mockolate.runner.MockolateRunner")]
    public class FileReferenceMockTests {

        [Mock]
        public var _fileRef:FileReference;

        [Test]
        public function TestMockFileReference():void {
            var bytes:ByteArray = new ByteArray();

            stub(_fileRef).getter("data").returns(bytes);
            stub(_fileRef).getter("name").returns("the name");

            assertThat(_fileRef.data, instanceOf(ByteArray));
            assertThat(_fileRef.data, sameInstance(bytes));
            assertThat(_fileRef.name, equalTo("the name"));
        }
    }
}

Specifically, it's the data property that is handled differently. In the Flex project it always returns null. If I set a breakpoint after the stub-statements the fileRef looks like this:

  • _fileRef mockolate.generated.FileReference32E51D...
    • [inherited]
      • data = null
    • creationDate = null
    • creator = null
    • modificationDate = null
    • name = "the name"
    • __ proxy __ = InterceptorProxyListener
    • size = 0
    • type = null

I'm using FlashBuilder 4.6 and Flex Framework 4.6.

Update: I have tested with Flex versions 4.1 and 4.5. Same result. I have also tested with a Flex Project run as Air Application, that works. So the problem seems to appear only when run in a browser. (I have tested both Firefox and Safari)

luddet avatar Dec 13 '12 01:12 luddet