-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreviewProvider.stencil
36 lines (32 loc) · 1.2 KB
/
PreviewProvider.stencil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import SwiftUI
import SnapshotTesting
import XCTest
@testable import SnapshotArticle
private func assertPreviewSnapshot<T: PreviewProvider>(_ target: T.Type,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line,
isDarkMode: Bool = false) {
for preview in T._allPreviews {
let content = preview.content
let viewController = content.toViewController()
if isDarkMode {
viewController.overrideUserInterfaceStyle = .dark
}
assertSnapshot(matching: viewController,
as: .image(on: .iPhone13),
file: file,
testName: testName,
line: line)
}
}
class PreviewSnapshotTests: XCTestCase {
{% for type in types.based.PreviewProvider %}
func test{{type.name}}() {
assertPreviewSnapshot({{type.name}}.self)
}
func test{{type.name}}_dark() {
assertPreviewSnapshot({{type.name}}.self, isDarkMode: true)
}
{% endfor %}
}