pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.

Home Page:https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snapshot testing a SwiftUI view with ScrollViewReader not expecting as Preview/Simulator

WedgeSparda opened this issue · comments

Hi, I'm snapshot testing a SwiftUI view which contains a ScrollView inside a ScrollViewReader. On the onAppear of the ScrollView I'm using the scrollReader to scroll to the bottom using
a @namespace

public struct MyView: View {

    @Namespace private var bottomID

    public var body: some View {
        ScrollViewReader { scrollReader in
            ScrollView([], showsIndicators: false) {
                // ...
                VStack {
                    // ...
                }
               .id(bottomID)
            }
            .onAppear {
                scrollReader.scrollTo(bottomID)
            }
        }
    }

The scrollview is disabled by default and its purpose is to set the content aligned to the bottom.

Is working correctly on the previews, simulator and device, but the snapshot is not performing the scroll, even using the .wait strategy and cheching with a breakpoint that scrollReader.scrollTo(bottomID) is being called.

What I'm doing wrong?

Thanks for your time

I'm running into the same issue with scrolling - I was getting inconsistent behaviour when the snapshot tests on CI were incorrectly scrolling even though on local machines they weren't.
I unfortunately had to turn off the scrolling for the snapshot tests completely.
Would be great if there was a solution to run onAppear code for snapshots.