Last active
July 6, 2023 16:40
-
-
Save lukeredpath/96ac8bfea295f0b729408ecce694ca26 to your computer and use it in GitHub Desktop.
BindingEquality bug in TCA 0.55.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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