Assert Some with FsUnit
I am trying to check that my function returns Some(x)
testedFunc() |> should be (sameAs Some)
testedFunc() |> should be Some
testedFunc() |> should equal Some
Everyone doesn't work. I would rather not use:
match testedFunc() with
| Some -> Pass()
| None -> Fail()
Does anyone know how to do this?
source to share
I haven't really used FsUnit, but something like this should work ...
testedFunc() |> Option.isSome |> should be true
Or, because the option already has an IsSome property, you can do that, but be careful - this is different from a function Option.isSome
.
testedFunc().IsSome |> should be true
A third approach would be to put together the function you are testing with Option.isSome
to get a function that returns a boolean directly. It's not that useful in this example, but if you need to test the parameter return function multiple times with different inputs, this approach can help reduce duplicate code.
let testedFunc = testedFunc >> Option.isSome
testedFunc() |> should be true
source to share