swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

Circle color not showing in Snapshot after updating the progress value on .onAppear SwiftUI

Open ishayan18 opened this issue 3 years ago • 1 comments

I am animating circle and OnAppear block I am updating the current progress of the circle

public struct CountdownProgressCircle: View {
  @Binding public var progress: TimeInterval

  public var body: some View {
      Circle()
        .trim(from: 0.0, to: CGFloat(min(progress, 1.0)))
        .foregroundColor(Color.green)
        .rotationEffect(Angle(degrees: 270.0))
        .animation(.linear)
  }
}
.onAppear(perform: {
          currentProgress = state.currentProgress
        })

I am using wait of 5 seconds assertSnapshot(matching: view, as: .wait(for: 5.0, on: .image), named: "Setup")

My Swift previous shows me below view Screenshot 2021-03-23 at 3 22 57 PM

Snapshot output: Screenshot 2021-03-23 at 3 23 57 PM

The output should be exactly the same as swiftUI preview but I think there is an issue while taking a snapshot

ishayan18 avatar Mar 23 '21 10:03 ishayan18

I am going through a similar issue:

I am having a view which uses a custom of the .redacted() feature to show loading placeholders, and for the animation I trigger onAppear the boolean state to be set to true. On preview and when running it works just well, but the snapshot tests are not detecting such bool update.

I have the impression that when running the tests we need to force onAppear to be run, so our values update and our views change accordingly. Anyone could help us here?

pedrosolisgarcia avatar May 09 '21 20:05 pedrosolisgarcia