-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContentViewTests.swift
More file actions
56 lines (48 loc) · 1.77 KB
/
ContentViewTests.swift
File metadata and controls
56 lines (48 loc) · 1.77 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@testable import Counter
import XCTest
import ViewInspector
final class ContentViewTests: XCTestCase {
@MainActor
func test_initialCount() throws {
let sut = ContentView()
let count = try sut.inspect().find(viewWithAccessibilityIdentifier: "count").text().string()
XCTAssertEqual(count, "0")
}
// begin-snippet: with_boilerplate
@MainActor
func test_incrementOnce_withBoilerplate() throws {
var sut = ContentView()
let expectation = sut.on(\.viewInspectorHook) { view in
try view.find(viewWithAccessibilityIdentifier: "increment").button().tap()
let count = try view.find(viewWithAccessibilityIdentifier: "count").text().string()
XCTAssertEqual(count, "1")
}
ViewHosting.host(view: sut)
defer { ViewHosting.expel() }
wait(for: [expectation], timeout: 0.4)
}
// end-snippet
// begin-snippet: with_testable_view
@MainActor
func test_incrementOnce_withTestableView() throws {
var sut = ContentView()
inspectChangingView(&sut) { view in
try view.find(viewWithAccessibilityIdentifier: "increment").button().tap()
let count = try view.find(viewWithAccessibilityIdentifier: "count").text().string()
XCTAssertEqual(count, "1")
}
}
// end-snippet
// begin-snippet: scannable
@MainActor
func test_incrementOnce_scannable() throws {
var sut = ContentView()
var count: String?
inspectChangingView(&sut) { view in
try view.find(viewWithAccessibilityIdentifier: "increment").button().tap()
count = try view.find(viewWithAccessibilityIdentifier: "count").text().string()
}
XCTAssertEqual(count, "1")
}
// end-snippet
}