RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

Add support for Image.prefetch() #96

Closed m-vdb closed 7 years ago

m-vdb commented 8 years ago

Hi there,

First of all thanks for this nice project, it's really helping me with the tests :)

Here is a small PR to add support to Image.prefetch(). I didn't see any test that I could add but LMK if and where I can write some.

RealOrangeOne commented 8 years ago

Im unfamiliar with what prefetch actually does? Surely theres something we can add besides a blank function?

m-vdb commented 8 years ago

Image.prefetch() is useful to pre-download a remote url (an image url) and save it to the disk for later use. I use it in order to avoid glitches when displaying remote images. We could for instance initialize a static 'cache' on the Image and save the urls there, but I don't think it's a real good idea to implement a custom behavior.

(In my tests I would use it in concordance with sinon.stub() to verify that Image.prefetch() is called with the right urls)

RealOrangeOne commented 8 years ago

Ah ok, sounds like a good idea. If image.prefetch is meant to return something, it might be worth returning something related to it's input, trying to replicate the functions IO instead of something dumb like this

m-vdb commented 7 years ago

not sure I understand what you mean. The prefetch() method doesn't return anything. And I think it would be better to leave the mocking part to the tester (by using sinon or any other mocking library).

RealOrangeOne commented 7 years ago

Ah, I didnt realise it didnt return anything, in that case I think this is fine for a mock. Merging