Test case fails because of StackState's hidden values. #2412
Replies: 2 comments 6 replies
-
Hi @cihankisakurek, this is discussed in our episodes and in the docs, but in order for Instead of doing that there are helpers on state.path[id: 0, case: /Path.State.feature] = … This will preserve the IDs and allow you to mutate state. Also, this is not an issue with the library so I am going to convert it to a discussion. Feel free to ask more questions over there. |
Beta Was this translation helpful? Give feedback.
-
I ran into a similar problem while testing path mutations. In my setup, child features use delegate actions to notify a root feature to modify the navigation stack. Here, the @Reducer
struct Child {
enum Action {
case itemTapped
}
}
struct ChildView: View {
let store: StoreOf<Child>
var body: some View {
Button("Item") {
store.send(.itemTapped)
}
}
} The @Reducer
struct Root {
@Reducer(state: .equatable)
enum Path {
case child(Child)
case other(Other)
}
struct State: Equatable {
var path = StackState<Path.State>()
}
enum Action {
case path(StackAction<Path.State, Path.Action>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .path(.element(_, action: .child(.itemTapped))):
state.path.append(.other(Other.State()))
return .none
case .path:
return .none
}
}
.forEach(\.path, action: \.path)
}
} This setup works fine. Here's how I expect to test that the navigation stack is modified correctly: @MainActor
func testItemTapped() async {
let store = TestStore(
initialState: Root.State(
path: StackState([
.child(Child.State())
])
),
reducer: { Root() }
)
await store.send(.path(.element(id: 0, action: .child(.itemTapped)))) {
$0.path = StackState([
.child(Child.State()),
.other(Other.State())
])
}
} This test fails as described by the OP because the StackElementID's don't line up. If instead of explicitly describing the state, I use mutations, the test passes. await store.send(.path(.element(id: 0, action: .child(.itemTapped)))) {
$0.path.append(.other(Other.State()))
} This isn't a huge issue, but the test feels less satisfying because I'm not really confirming the entire contents of the stack state. Am I executing these tests correctly? |
Beta Was this translation helpful? Give feedback.
-
Description
Hello,
I am currently updating my TCA 0.55 project to TCA 1.1.0 and new navigation store. Migration part went pretty well however I am stuck in an issue with test store.
Test function looks like this.
and the error output is
which was very confusing for me and I dug a little bit deeper and in TestStore.swift:1019 there is an equality check that fails and if I print and diff the expectedWhenGivenPreviousState and actual state I got this
which confused me some more.
Also I have a very similar test case that works.
Only difference I can see is that in the second case I send the action .navigateToTournament and in failing case it is a receive.
Thanks in advance.
Checklist
main
branch of this package.Expected behavior
TestStore's send and receive calls should behave same.
Actual behavior
there is a discrepancy between TestStore.send and TestStore.receive
Steps to reproduce
please see the explanation
The Composable Architecture version information
1.1.0
Destination operating system
iOS 16
Xcode version information
Version 14.3 (14E222b)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions