TestStore and implicitly returned actions #531
-
Is it by design that action returned concatenated effects in I.e. in following reducer: enum Action { case onAppear, testA, testB }
testReducer = { ...
case .onAppear: return .concatenate(
.init(value: testA), .init(value: .testB)
)
} The test case fails: testExample() {
...
testStore.send(.onAppear)
testStore.receive(.testB) // ❌ will not be received
// Expected to receive an action, but received none.
} This is suuuuuper confusing to me as a newb to TCA testing. I would literally put my hand into the fire that the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Can you provide a fully compiling example to show the behavior you are seeing versus the behavior you expect? FWIW this test passes and it is what I would expect: func testConcatenate() {
enum Action { case onAppear, testA, testB }
let store = TestStore(
initialState: 0,
reducer: Reducer<Int, Action, Void> { state, action, _ in
switch action {
case .onAppear:
return .concatenate(
.init(value: .testA),
.init(value: .testB)
)
case .testA:
return .none
case .testB:
return .none
}
},
environment: ()
)
store.send(.onAppear) ✅
store.receive(.testA) ✅
store.receive(.testB) ✅
} |
Beta Was this translation helpful? Give feedback.
-
The So you will never want to concatenate something after it. I suppose you could create an alternate API of this dependency that separates a Also, the return .merge(
env.locationManager.create(...),
env.locationManager.requestLocation(...)
) One last thing, the endpoint |
Beta Was this translation helpful? Give feedback.
The
.create
endpoint on the location manager is a long living effect because it is what sends back all of the delegate methods from the location manager delegate:https://github.com/pointfreeco/composable-core-location/blob/9e9f1809ba52cc5f1b157c726b87e4e7ce4dbefd/Sources/ComposableCoreLocation/Interface.swift#L178-L239
So you will never want to concatenate something after it. I suppose you could create an alternate API of this dependency that separates a
.create
endpoint from a.delegate
endpoint, but I don't see a benefit to doing that right now.Also, the
.merge
in this cause is fine because.create
executes synchronously to create the location manager, and so it completely fine to ref…