Automattic / Gravatar-SDK-iOS

Gravatar SDK is a Swift library that allows you to integrate Gravatar features into your own iOS applications.
https://gravatar.com
Mozilla Public License 2.0
52 stars 5 forks source link

Add unit tests for SwiftUI views #539

Open pinarol opened 3 weeks ago

pinarol commented 3 weeks ago

Let's check how we can add unit tests for SwiftUI Views.

We can try snapshotting with the existing snapshot library, like:

func testMyViewSnapshot() {
        // Create the SwiftUI view
        let view = MyView()

        let hostingController = UIHostingController(rootView: view)
        hostingController.view.frame = CGRect(x: 0, y: 0, width: 200, height: 100)

        assertSnapshot(matching: hostingController, as: .image)
    }