Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick proposal to fix .wait method #742

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JustasL
Copy link

@JustasL JustasL commented Jun 16, 2023

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

@markst
Copy link

markst commented Jun 26, 2023

@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

@markst
Copy link

markst commented Jun 27, 2023

@JustasL can you make amends to bring in these changes? markst@029c66a

Also make it clear to mention that this delay needs to occur between presentation to window prepareView & renderer.
#717 (comment)

@JustasL
Copy link
Author

JustasL commented Jun 27, 2023

@markst updated PR, although was not sure where to put comment about:

delay needs to occur between presentation to window prepareView & renderer.

@kamvoick
Copy link

kamvoick commented Jul 16, 2023

SwiftUI View does not work also with wait strategy, and requires this workaround here

And i confirm that adding this delay solves it with SwiftUI

@lihao6485
Copy link

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.

@r3econ
Copy link

r3econ commented Sep 14, 2023

Is there any timeline for fixing it? The problem affects our test workflows

@WJacobsNL
Copy link

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 :)

@jmorgaz-freenow
Copy link

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?

@taquitos
Copy link

@stephencelis, would you mind taking a peek at this? I'd hate to have to fork the project just to pull this 🙃

@AF-cgi
Copy link

AF-cgi commented Feb 9, 2024

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?

@mbaikovets
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants