swift-snapshot-testing
swift-snapshot-testing copied to clipboard
Quick proposal to fix .wait method
As mentioned in this issue Snapshotting.wait
does not work UIViewController
if view
property is not accessed
From quick debugging it seems it's because view is created, then snapshotting waits for delay period, and only then it setups views and quickly disposes them
My proposed work-a-round is to actually delays test assertion from being ran
@JustasL makes more sense to extend Async
:
extension Async {
func delay(by timeInterval: TimeInterval) -> Async<Value> {
return Async<Value> { callback in
self.run { value in
DispatchQueue.main.asyncAfter(deadline: .now() + timeInterval) {
callback(value)
}
}
}
}
}
then you can chain:
addImagesForRenderedViews(view).sequence().delay(by: 1.0).run { views in
@JustasL can you make amends to bring in these changes? https://github.com/markst/swift-snapshot-testing/commit/029c66aa6ad8cf226025576dbd0289cfea5e800d
Also make it clear to mention that this delay needs to occur between presentation to window prepareView
& renderer
.
https://github.com/pointfreeco/swift-snapshot-testing/issues/717#issuecomment-1603426150
@markst updated PR, although was not sure where to put comment about:
delay needs to occur between presentation to window prepareView & renderer.
SwiftUI View does not work also with wait strategy, and requires this workaround here https://github.com/pointfreeco/swift-snapshot-testing/blob/dc46eeb3928a75390651fac6c1ef7f93ad59a73b/Sources/SnapshotTesting/Snapshotting/SwiftUIView.swift#L74
And i confirm that adding this delay solves it with SwiftUI
Thanks @JustasL, the new .delay function solved my issue when a view required to load mock network data on viewWillAppear
. We always getting inconsistence result, for example loading indicator is not dismiss when using .wait function.
@stephencelis possible to take a look this PR? Thanks.
Is there any timeline for fixing it? The problem affects our test workflows
We are currently putting our tests to Sleep in order to wait for loading to finish, would be helpful if this fix would get released :)
Thanks @JustasL for this workaround. I can confirm that works in our SwiftUI views too. We've created a fork including your changes but could be nice if those could be added in a regular release, any news about that?
@stephencelis, would you mind taking a peek at this? I'd hate to have to fork the project just to pull this 🙃
Any updates here?
@JustasL Could you update your PR to the latest api of this package? I ask you because there are some notice of deprecated api's like asseertShnapshot(matching: ...)
.
@markst Could you release a new version including of this fix?
Hello! @stephencelis , what should be done to move this proposal forward and introduce new version of package with this changes? If there anything we as community can help with - please, let us know.
Thank you in advance!
Hi! It's been a while since this MR is opened and maybe there is someone else besides @stephencelis that could help us with it?
@stephencelis is it posible to merge this fix?
Also waiting for a fix on this, what is the status?