Skip to content

Commit 7049d80

Browse files
authored
Merge pull request #5 from SwiftRex/darkModeSupport
Adds support for dark / light mode snapshots
2 parents 321a8e1 + 1a3e43e commit 7049d80

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

Sources/TestingExtensions/SnapshotTestBase.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,36 @@ open class SnapshotTestBase: XCTestCase {
3232
open func assertSnapshotDevices<V: View>(
3333
_ view: V,
3434
devices: [(name: String, device: ViewImageConfig)]? = nil,
35+
style: [UIUserInterfaceStyle] = [.unspecified],
3536
file: StaticString = #file,
3637
testName: String = #function,
3738
line: UInt = #line
3839
) {
39-
(devices ?? defaultDevices).forEach {
40-
let vc = UIHostingController(rootView: view)
40+
(devices ?? defaultDevices).forEach { config in
41+
style.forEach { uiStyle in
42+
let vc = UIHostingController(rootView: view)
43+
vc.overrideUserInterfaceStyle = uiStyle
4144

42-
assertSnapshot(
43-
matching: vc,
44-
as: .image(on: $0.device),
45-
file: file,
46-
testName: "\(testName)-\($0.name)",
47-
line: line
48-
)
45+
let suffix: String
46+
switch uiStyle {
47+
case .unspecified:
48+
suffix = ""
49+
case .light:
50+
suffix = "-light"
51+
case .dark:
52+
suffix = "-dark"
53+
@unknown default:
54+
fatalError("Unhandled UIUserInterfaceStyle \(uiStyle)")
55+
}
56+
57+
assertSnapshot(
58+
matching: vc,
59+
as: .image(on: config.device),
60+
file: file,
61+
testName: "\(testName)-\(config.name)\(suffix)",
62+
line: line
63+
)
64+
}
4965
}
5066
}
5167
}

0 commit comments

Comments
 (0)