Skip to content

Commit

Permalink
Add example test for get error
Browse files Browse the repository at this point in the history
  • Loading branch information
marner2 committed Aug 7, 2022
1 parent 090b6b1 commit 90ca052
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Elmish.WPF.Tests/BindingVmHelpersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ module Get =
GenX.auto<string> |> GenX.withNull |> checker
GenX.auto<obj> |> GenX.withNull |> checker

[<Fact>]
let ``should return error on bad typing`` () =
let binding = Binding.SubModel.opt (fun () -> []) >> Binding.mapModel (fun () -> None) <| ""

let dispatch msg =
failwith $"Should not dispatch, got {msg}"

let vmBinding =
Initialize(LoggingViewModelArgs.none, "Nothing", (fun _ -> failwith "Should not call get selected item"))
.Recursive((), dispatch, (fun () -> ()), binding.Data)
|> Option.defaultWith (fun () -> failwith $"Could not create VmBinding after passing in BindingData: {binding}")

let vmBinding2 = vmBinding |> MapOutputType.unboxVm

let getResult: Result<int, GetError> = Get("Nothing").Recursive((), vmBinding2)

test <@ getResult = Error (GetError.ToNullError ValueOption.ToNullError.ValueCannotBeNull) @>

module Set =

let checker<'t when 't : equality> (g: Gen<'t>) =
Expand Down

0 comments on commit 90ca052

Please sign in to comment.