Skip to content

Commit a39c73f

Browse files
committed
Add failing test using store.publisher in makeUIView
1 parent acd9bb8 commit a39c73f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/ComposableArchitectureTests/StorePerceptionTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,36 @@ final class StorePerceptionTests: BaseTCATestCase {
6868
render(FeatureView())
6969
}
7070

71+
@MainActor
72+
func testPerceptionCheck_ViewRepresentable_publisher() {
73+
#if canImport(UIKit)
74+
struct ViewRepresentable: UIViewRepresentable {
75+
let store = Store(initialState: Feature.State()) {
76+
Feature()
77+
}
78+
func makeUIView(context: Context) -> UILabel {
79+
let label = UILabel()
80+
let cancellable = store.publisher.sink { [weak label] state in
81+
label?.text = "\(state.count)"
82+
}
83+
objc_setAssociatedObject(label, cancellableKey, cancellable, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
84+
return label
85+
}
86+
func updateUIView(_ view: UILabel, context: Context) {}
87+
}
88+
render(ViewRepresentable())
89+
#endif
90+
}
91+
7192
@MainActor
7293
private func render(_ view: some View) {
7394
let image = ImageRenderer(content: view).cgImage
7495
_ = image
7596
}
7697
}
7798

99+
@MainActor private let cancellableKey = malloc(1)!
100+
78101
@Reducer
79102
private struct Feature {
80103
@ObservableState

0 commit comments

Comments
 (0)