agentsclimarketplace

Swiftui testing

Skill gabriel/swift-skills/skills/swiftui-testing

SwiftUI snapshot testing patterns using SwiftUISnapshotTesting. Use when writing snapshot tests, choosing between assertRender and assertSnapshot, setting up visual regression testing, or configuring device simulation for SwiftUI views. Triggers on: "snapshot test", "SwiftUI test", "assertRender", "assertSnapshot", "visual regression", "snapshot testing", "SwiftUI snapshot", "device simulation test".From its SKILL.md

Install
npx -y skills add gabriel/swift-skills --skill swiftui-testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.1 KB, as published. Nobody here has run it

SwiftUI Snapshot Testing Patterns

Overview

Snapshot testing for SwiftUI views using SwiftUISnapshotTesting (wraps pointfreeco/swift-snapshot-testing). Two rendering strategies: pure SwiftUI (assertRender) and UIKit-hosted (assertSnapshot).

When to Use Which

assertRenderassertSnapshot
RenderingPure SwiftUI (ImageRenderer)UIKit-hosted (UIHostingController)
SpeedFasterSlower
AccuracyGood for pure SwiftUIBetter for complex hierarchies
UIKit componentsNo (NavigationStack, TabView)Yes
Cross-platformiOS + macOSiOS + macOS

Rule of thumb: Start with assertRender. Switch to assertSnapshot if the view uses NavigationStack, TabView, or other UIKit-backed components.

Quick Start

import SwiftUISnapshotTesting
import Testing

@Test @MainActor
func testCard() throws {
    let view = CardView(title: "Hello")
    assertRender(view: view, device: .size(400, 400))
}

@Test @MainActor
func testScreen() throws {
    let view = NavigationStack { MyScreen() }
    assertSnapshot(view: view, device: .iOS(width: 375, height: 812))
}

Device Options

  • .size(width, height) — Custom size, any platform
  • .iOS(width, height) — iOS device simulation
  • .macOS(width, height) — macOS window simulation
  • .any — Default size (400x1200 iOS, 1200x800 macOS)

Installation

.package(url: "https://github.com/gabriel/swiftui-snapshot-testing", from: "0.1.12")
// Add "SwiftUISnapshotTesting" to test target dependencies

References

Read references/snapshot-testing.md for async testing patterns, recording modes, and full API details.

Keep looking

Skills are one crate of 608,475. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.