我试图使用FsUnit.Xunit断言某种异常类型和消息。有一些throwWithMessage函数随FsUnit而来。但是,当使用它代替throw函数时,fsc会发出以下错误:
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'这是一个不会编译的测试:
[<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我不知道这里出了什么问题。
版本:
发布于 2018-04-16 22:38:35
韦尔普,我漏掉了一些括号。这样做是可行的:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should (throwWithMessage "Some message") typeof<ArgumentException> https://stackoverflow.com/questions/49867081
复制相似问题