Skip to content

Commit 6ddfa1b

Browse files
committed
Fix DEBUG-mode perception check test to cover iOS 17+
1 parent 34cb935 commit 6ddfa1b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

Tests/ComposableArchitectureTests/StorePerceptionTests.swift

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,30 @@ final class StorePerceptionTests: BaseTCATestCase {
3333

3434
@MainActor
3535
func testPerceptionCheck_AccessStateWithoutTracking() {
36-
if #unavailable(iOS 17, macOS 14, tvOS 17, watchOS 10) {
37-
@MainActor
38-
struct FeatureView: View {
39-
let store = Store(initialState: Feature.State()) {
40-
Feature()
41-
}
42-
var body: some View {
43-
Text(store.count.description)
44-
}
36+
@MainActor
37+
struct FeatureView: View {
38+
let store = Store(initialState: Feature.State()) {
39+
Feature()
4540
}
46-
XCTExpectFailure {
47-
render(FeatureView())
48-
} issueMatcher: {
49-
$0.compactDescription == """
50-
failed - Perceptible state was accessed but is not being tracked. Track changes to state by \
51-
wrapping your view in a 'WithPerceptionTracking' view. This must also be done for any \
52-
escaping, trailing closures, such as 'GeometryReader', `LazyVStack` (and all lazy \
53-
views), navigation APIs ('sheet', 'popover', 'fullScreenCover', etc.), and others.
54-
"""
41+
var body: some View {
42+
Text(store.count.description)
5543
}
5644
}
45+
#if DEBUG
46+
let previous = Perception.isPerceptionCheckingEnabled
47+
Perception.isPerceptionCheckingEnabled = true
48+
defer { Perception.isPerceptionCheckingEnabled = previous }
49+
XCTExpectFailure {
50+
render(FeatureView())
51+
} issueMatcher: {
52+
$0.compactDescription == """
53+
failed - Perceptible state was accessed but is not being tracked. Track changes to state by \
54+
wrapping your view in a 'WithPerceptionTracking' view. This must also be done for any \
55+
escaping, trailing closures, such as 'GeometryReader', `LazyVStack` (and all lazy \
56+
views), navigation APIs ('sheet', 'popover', 'fullScreenCover', etc.), and others.
57+
"""
58+
}
59+
#endif
5760
}
5861

5962
@MainActor

0 commit comments

Comments
 (0)