bindings(action:)

Returns a binding view store for this store.

TestStore.swift:2578
@MainActor func bindings<ViewAction>(action toViewAction: CaseKeyPath<Action, ViewAction>) -> BindingViewStore<State> where State == ViewAction.State, Action : CasePathable, ViewAction : BindableAction

Parameters

toViewAction

A case path from action to a bindable view action.

Returns

A binding view store.

Useful for testing view state of a store.

let store = TestStore(LoginFeature.State()) {
  Login.Feature()
}
await store.send(.view(.set(\.$email, "blob@pointfree.co"))) {
  $0.email = "blob@pointfree.co"
}
XCTAssertTrue(
  LoginView.ViewState(store.bindings(action: \.view))
    .isLoginButtonDisabled
)

await store.send(.view(.set(\.$password, "whats-the-point?"))) {
  $0.password = "blob@pointfree.co"
  $0.isFormValid = true
}
XCTAssertFalse(
  LoginView.ViewState(store.bindings(action: \.view))
    .isLoginButtonDisabled
)