Reputation: 541
I'm trying to assert a certain exception type and message using FsUnit.Xunit.
There is some throwWithMessage
function that comes with FsUnit. However, when using it instead of the throw
function fsc emits the following errors:
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
C:\src\foo.fs(29,19): error FS0001: The type ''a -> NHamcrest.Core.CustomMatcher<obj>' is not compatible with the type 'NHamcrest.IMatcher<obj>'
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
This is the test that won't compile:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should throwWithMessage "Some message" typeof<ArgumentException> //This is line 29
//^ column index 12 is here
//^ here is column index 19
I'm not sure what's wrong here.
Versions:
Upvotes: 4
Views: 443
Reputation: 541
Welp, I missed some brackets. This works:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should (throwWithMessage "Some message") typeof<ArgumentException>
Upvotes: 6