Provide means to delay snapshot
markst opened this issue · comments
In our views we have UIImageView
which fetches from an image url.
For testing purposes these test assets are loaded from load bundle:
public enum TestResource {
public static func imageURL(named: String, ext: String) -> URL? {
Bundle.module.url(
forResource: named,
withExtension: ext,
subdirectory: nil
But for snapshots to work there needs to be a minor delay for completion closures to be called in which to display the image.
i.e:
let failure = verifySnapshot(
matching: try value(),
as: .wait(
for: wait,
on: .image(
drawHierarchyInKeyWindow: false,
precision: defaultPerceptualPrecision,
size: size
)
),
Happy to work on this, but not sure how we might conditionally use a delay.
Perhaps PrefireProvider
could expect a config to be returned which could have some additional attributes?
Yes, I think we can make a configuration that will provide some custom settings for Snapshots. For example, add delay and accuracy there:
struct TestView_Previews: PrefireProvider {
static var previews: some View {
TestView()
.snapshot(delay: 0.1, precision: 1)
}
}
@BarredEwe not sure view modifier will work given we can't capture the preference synchronously.
unless we triggered a draw of the view prior to assertSnapshot
?
I made this improvement and posted a pull request 🥳