I am not sure how to write my test in FsUnit.Xunit
.
I want to check that at least one element in my list satisfies a predicate. I know how to write this using should be True
, but usually you can get better error messages by using the specialized functions.
Hopefully this code makes it clear what I am trying to achieve:
open Xunit
open FsUnit.Xunit
type Foo =
{
X : int
}
[<Fact>]
let ``squares`` () =
let xs =
[ { X = 1 }; { X = 2 }; { X = 3 } ]
|> List.map (fun foo -> { X = foo.X * foo.X })
actual
|> should exists (satisfies (fun foo -> foo.X = 9)) // Not real code