Skip to content

Commit

Permalink
Implements trigger to render before assertion to help rendering async…
Browse files Browse the repository at this point in the history
… stuff on wait strategy (#61)
  • Loading branch information
LukasLiebl authored Jul 24, 2023
1 parent 8488c1c commit 1bdec3c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/SnapshotTestingExtensions/SnapshotTestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ open class SnapshotTestBase: XCTestCase {
devices: [(name: String, device: ViewImageConfig)]? = nil,
style: [UIUserInterfaceStyle] = [.unspecified],
imageDiffPrecision: Float = 1.0,
shouldRecord: Bool = false,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
Expand All @@ -38,6 +39,7 @@ open class SnapshotTestBase: XCTestCase {
as: .image(on: config.device, precision: imageDiffPrecision),
style: style,
config: config,
record: shouldRecord,
file: file,
testName: testName,
line: line
Expand All @@ -50,6 +52,7 @@ open class SnapshotTestBase: XCTestCase {
devices: [(name: String, device: ViewImageConfig)]? = nil,
style: [UIUserInterfaceStyle] = [.unspecified],
imageDiffPrecision: Float = 1.0,
shouldRecord: Bool = false,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line,
Expand All @@ -61,6 +64,7 @@ open class SnapshotTestBase: XCTestCase {
as: .wait(for: wait, on: .image(on: config.device, precision: imageDiffPrecision)),
style: style,
config: config,
record: shouldRecord,
file: file,
testName: testName,
line: line
Expand All @@ -73,6 +77,7 @@ open class SnapshotTestBase: XCTestCase {
as snapshotting: Snapshotting<UIViewController, UIImage>,
style: [UIUserInterfaceStyle] = [.unspecified],
config: (name: String, device: ViewImageConfig),
record: Bool,
file: StaticString,
testName: String,
line: UInt
Expand All @@ -81,6 +86,9 @@ open class SnapshotTestBase: XCTestCase {
let vc = UIHostingController(rootView: view)
vc.overrideUserInterfaceStyle = uiStyle

// called to trigger rendering e.g. for AsyncImage
vc.viewDidAppear(false)

let suffix: String
switch uiStyle {
case .unspecified:
Expand All @@ -96,6 +104,7 @@ open class SnapshotTestBase: XCTestCase {
assertSnapshot(
matching: vc,
as: snapshotting,
record: record,
file: file,
testName: "\(testName)-\(config.name)\(suffix)",
line: line
Expand Down

0 comments on commit 1bdec3c

Please sign in to comment.