Swiftpack.co - john-flanagan/SnapshotTestingImageRender as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by john-flanagan.
john-flanagan/SnapshotTestingImageRender 1.0.0
SnapshotTesting strategy based on SwiftUI's ImageRenderer class
⭐️ 0
🕓 1 week ago
iOS tvOS
.package(url: "https://github.com/john-flanagan/SnapshotTestingImageRender.git", from: "1.0.0")

SnapshotTestingImageRender

A extension to SnapshotTesting that adds a SwiftUI snapshot strategy using SwiftUI.ImageRender to snapshot the View.

Usage

Once installed, no additional configuration is required. You can import the ImageRenderSnapshotStrategy module, call into SnapshotTesting following their usage guide but provide the .imageRender strategy as below.

import XCTest
import SnapshotTesting
import SnapshotTestingImageRender

class ContentViewTests: XCTestCase {
  func testSnapshots() {
    let view = ContentView()
    assertSnapshot(matching: view, as: .imageRender)
  }
}

Installation

Xcode 11

⚠️ Warning: By default, Xcode will try to add the SnapshotTestingImageRender package to your project's main application/framework target. Please ensure that SnapshotTestingImageRender is added to a test target instead, as documented in the last step, below.

  1. From the File menu, navigate through Swift Packages and select Add Package Dependency….
  2. Enter package repository URL: https://github.com/john-flanagan/SnapshotTestingImageRender
  3. Confirm the version and let Xcode resolve the package
  4. On the final dialog, update SnapshotTestingImageRender's Add to Target column to a test target that will contain snapshot tests (if you have more than one test target, you can later add SnapshotTestingImageRender to them by manually linking the library in its build phase)

Swift Package Manager

If you want to use SnapshotTestingImageRender in any other project that uses Swift Package Manager, add the package as a dependency in Package.swift:

dependencies: [
  .package(url: "https://github.com/john-flanagan/SnapshotTestingImageRender.git", from: "1.0.0"),
]

Next, add SnapshotTestingImageRender as a dependency of your test target:

targets: [
  .target(
    name: "MyApp"
  ),

  .testTarget(
    name: "MyAppTests",
    dependencies: [
      .target(name: "MyApp"),
      .product(name: "SnapshotTestingImageRender", package: "SnapshotTestingImageRender"),
    ]
  ),
]

License

This library is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics