Note that there are some explanatory texts on larger screens.

plurals
  1. POMocking FileReference.data with mockolate?
    primarykey
    data
    text
    <p>I'm trying to mock FileReference in a flex project I'm working on.</p> <p>Stubbing out some properties, such as name and size works fine, but data just refuses to work. Here is code that illustrates the problem:</p> <pre><code>[Test] public function FileReferenceMockTest():void { var frMock:FileReference = nice(FileReference); var bytes:ByteArray = new ByteArray(); stub(frMock).getter("data").returns(bytes); stub(frMock).getter("name").returns("filename"); assertThat(frMock.name, equalTo("filename")); // works assertThat(frMock.data, sameInstance(bytes)); // Fails and says that frMock.data is null } </code></pre> <p>If I set a breakpoint and check frMock in the debugger it looks like this:</p> <pre><code>frMock [inherited] data = null creationDate = null creator = null modificationDate = null name = "filename" __proxy__ = InterceptorProxyListener ... </code></pre> <p>As you can see, data is treated differently by the mock.</p> <p>I've been banging my head against this problem for several hours now and could really really use some help figuring this out.</p> <p>Update:<br> The code works when run either as a Flex Library Project or a Flex Project (Air). It's when the code is run in a browser plugin that it fails. A check in the debugger in the library project also shows that the data property is not nested inside [Inherited], but on the same level as the other properties.</p> <p>Update:<br> I encountered the same problem with URLLoader, but this time the other way around. Mocking of the URLLoader only works when running the tests in a browser plugin.<br> Since I'm creating a class to handle local and remote file loading, using either FileReference or URLLoader, depending on input, I'm effectively prevented from unit testing this class completely. :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload