Replies: 1 comment 1 reply
-
Hi @nesium! Thanks for the example and context. This is a known issue and a thorny one. The test store was designed long before shared state, and it relies on eagerly performing all effects and snapshotting the changes to the value types along the way. Because We do have a branch showing how lazy evaluation would work, and if you point to it you'll see the tests behave how you expect: https://github.com/pointfreeco/swift-composable-architecture/tree/lazy-test-store Unfortunately this breaks other expectations when it comes to effect ordering, and so it would be a breaking change to tests. We do think there is a path forward to fixing this, but it will take some time and might be a breaking change. In the meantime, at the very least the tests are deterministic, if unintuitive as you point out. |
Beta Was this translation helpful? Give feedback.
-
Hello!
While upgrading from 0.56.0 to 1.17.1 (🥵) I've replaced a couple of generic state wrappers with shared state. Now, trying to fix my tests, I somewhat struggle with - what I would call - pretty unintuitive behavior with
@Shared
state.Let's assume this simple Reducer and State…
Returning the
send
effects is quite contrived, but these could either be async responses from a HTTP API or actions triggered from long lived effects like a WebSocket.Let's test the simple case first…
This looks perfectly reasonable. I send an action and assert the change. It works just like regular state with value semantics.
Now let's look at the second case where an effect is returned so that a second action is sent back into the reducer…
This is where it gets weird. While the
store.assert
works as expected, the assert closures instore.send
andstore.receive
do not. Somehow I only have to assert the result of the second action sent to the reducer.I'm not sure what to make of this. It feels like fudging the tests until they work and I'm afraid that it makes the tests difficult to understand. Am I missing something?
This appears to be partially related to this discussion: #3308
Beta Was this translation helpful? Give feedback.
All reactions