Skip to content

Commit

Permalink
Assertion interceptor (#62)
Browse files Browse the repository at this point in the history
* Removes flag to record as it it was used for testing purposes

* Refactors SnapshotTestBase api to have an interceptor before asserting the snapshot and only triggering a render update for the wait strategy
  • Loading branch information
LukasLiebl authored Jul 25, 2023
1 parent 1bdec3c commit 80ad089
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Sources/SnapshotTestingExtensions/SnapshotTestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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 @@ -39,7 +38,6 @@ 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 @@ -52,7 +50,6 @@ 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 @@ -64,7 +61,10 @@ open class SnapshotTestBase: XCTestCase {
as: .wait(for: wait, on: .image(on: config.device, precision: imageDiffPrecision)),
style: style,
config: config,
record: shouldRecord,
preAssertionInterceptor: { vc in
// called to trigger rendering e.g. for AsyncImage
vc.viewDidAppear(false)
},
file: file,
testName: testName,
line: line
Expand All @@ -77,7 +77,7 @@ open class SnapshotTestBase: XCTestCase {
as snapshotting: Snapshotting<UIViewController, UIImage>,
style: [UIUserInterfaceStyle] = [.unspecified],
config: (name: String, device: ViewImageConfig),
record: Bool,
preAssertionInterceptor: ((UIViewController) -> Void)? = nil,
file: StaticString,
testName: String,
line: UInt
Expand All @@ -86,8 +86,7 @@ open class SnapshotTestBase: XCTestCase {
let vc = UIHostingController(rootView: view)
vc.overrideUserInterfaceStyle = uiStyle

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

let suffix: String
switch uiStyle {
Expand All @@ -104,7 +103,6 @@ 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 80ad089

Please sign in to comment.