Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Last active July 6, 2023 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/96ac8bfea295f0b729408ecce694ca26 to your computer and use it in GitHub Desktop.
Save lukeredpath/96ac8bfea295f0b729408ecce694ca26 to your computer and use it in GitHub Desktop.
BindingEquality bug in TCA 0.55.0
import ComposableArchitecture
import XCTest
struct BindingTestFeature: ReducerProtocol {
struct State: Equatable {
@BindingState
var value: Int = 0
}
enum Action: Equatable, BindableAction {
case binding(BindingAction<State>)
case setValueDelayed(Int)
}
@Dependency(\.mainQueue)
private var mainQueue
var body: some ReducerProtocolOf<Self> {
BindingReducer()
Reduce<State, Action> { state, action in
switch action {
case .setValueDelayed(let value):
return .run { send in
try await mainQueue.sleep(for: .seconds(1))
await send(.set(\.$value, value))
}
case .binding:
return .none
}
}
}
}
@MainActor
final class BindingEqualityTestsTests: XCTestCase {
func testBindingSendReceive() async {
let store = TestStore(
initialState: BindingTestFeature.State(),
reducer: BindingTestFeature()
)
await store.send(.binding(.set(\.$value, 1))) {
$0.value = 1
}
store.dependencies.mainQueue = .immediate
await store.send(.setValueDelayed(2))
await store.receive(.binding(.set(\.$value, 2))) {
$0.value = 2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment