You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to write a unit test that will snapshot a View that has an observableState reducer, however doing so causes bad access. I have produced a simple example to reproduce this below:
View and Reducer:
public struct DummyViewCrashes: View {
let store: StoreOf<DummyReducerCrashes>
public init(store: StoreOf<DummyReducerCrashes>) {
self.store = store
}
public var body: some View {
return Text("")
}
}
@Reducer
public struct DummyReducerCrashes {
@ObservableState
public struct State: Equatable {}
public enum Action {}
public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
}
}
}
}
public struct DummyViewNoCrashes: View {
let store: StoreOf<DummyReducerNoCrashes>
public init(store: StoreOf<DummyReducerNoCrashes>){
self.store = store
}
public var body: some View {
return Text("")
}
}
@Reducer
public struct DummyReducerNoCrashes {
public struct State: Equatable {}
public enum Action {}
public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
}
}
}
}
Unit test:
@MainActor
func testCrash() async throws {
let view = DummyViewCrashes(store: .init(initialState: .init(), reducer: {
DummyReducerCrashes()
}))
assertSnapshot(of: view, as: .dump)
}
@MainActor
func testNoCrash() async throws {
let view = DummyViewNoCrashes(store: .init(initialState: .init(), reducer: {
DummyReducerNoCrashes()
}))
assertSnapshot(of: view, as: .dump)
}`
By contrast, a vanilla Observable model and SwiftUI vanilla view, does not crash:
View and model:
`@available(iOS 17.0, *)
@Observable
public class ObservableModel {
let someText = ""
}
@available(iOS 17.0, *)
public struct VanillaView: View {
@State var observableModel: ObservableModel
public init(observableModel: ObservableModel) {
self.observableModel = observableModel
}
public var body: some View {
return Text("")
}
}
The test crashes with Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cbdbbe8) on let mirror = Mirror(reflecting: value) in private func snap<T>(_ value: T, name: String? = nil, indent: Int = 0) -> String {... in the Snapshotting class
Reproducing project
No response
The Composable Architecture version information
1.16.1
Destination operating system
iOS 18 iPhone 16 Pro sim
Xcode version information
Xcode 16.2
Swift Compiler version information
No response
The text was updated successfully, but these errors were encountered:
aj2109
added
the
bug
Something isn't working due to a bug in the library.
label
Jan 10, 2025
Description
I am trying to write a unit test that will snapshot a View that has an observableState reducer, however doing so causes bad access. I have produced a simple example to reproduce this below:
View and Reducer:
Unit test:
Test:
Checklist
main
branch of this package.Expected behavior
The test runs and passes or fails
Actual behavior
The test crashes with
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16cbdbbe8)
onlet mirror = Mirror(reflecting: value)
inprivate func snap<T>(_ value: T, name: String? = nil, indent: Int = 0) -> String {...
in the Snapshotting classReproducing project
No response
The Composable Architecture version information
1.16.1
Destination operating system
iOS 18 iPhone 16 Pro sim
Xcode version information
Xcode 16.2
Swift Compiler version information
No response
The text was updated successfully, but these errors were encountered: