facebookarchive / ios-snapshot-test-case

Snapshot view unit tests for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing views with asynchronous images..

simonpac opened this issue · comments

commented

Hello, I am working on implementing ui testing with this framework.

I have a view which contains an image that does not immediately load. Therefore, in my reference image, I am seeing an empty image since it has not loaded yet.

What is the proper way to run a snapshot with asynchronous loading images?

@simonpac There's no native support for asynchronous snapshot tests.
You could could consider 3 things:

  • avoid asynchronous image downloading: in my team we mock images by providing sample data which contains URL to local images. Tests are always fast.
  • add some notification / observer which will trigger expectation.fulfill() and after this make snapshot. May increase test time, may fail.
  • use RunLoop.main.run(until: Date(timeIntervalSinceNow: 5)). Will increase test time, may fail.