Elm 测试:如何检查结果是否为错误?
Elm testing: how to check if a Result is an Err?
我正在为 return 结果的函数编写测试。我如何测试它 "is" 一个 Err(或 Ok,就此而言)?
\() -> Expect.equal expectedFailure (Err _)
无效。
如何解码非参数?
我可能错过了一个更优雅的解决方案,但我个人会写一个辅助函数。
resultOk result =
case result of
Ok _ -> True
Err _ -> False
然后在你的测试中
Expect.true "expected this to be OK" (resultOk <| Ok "All good")
Expect.false "expected this to be an error" (resultOk <| Err "Oh no!")
如果测试失败,Expect.true
和 Expect.false
将打印一个字符串,然后是一个应该为真(在 Expect.true
的情况下)或假(在Expect.false
).
的情况
我正在为 return 结果的函数编写测试。我如何测试它 "is" 一个 Err(或 Ok,就此而言)?
\() -> Expect.equal expectedFailure (Err _)
无效。
如何解码非参数?
我可能错过了一个更优雅的解决方案,但我个人会写一个辅助函数。
resultOk result =
case result of
Ok _ -> True
Err _ -> False
然后在你的测试中
Expect.true "expected this to be OK" (resultOk <| Ok "All good")
Expect.false "expected this to be an error" (resultOk <| Err "Oh no!")
如果测试失败,Expect.true
和 Expect.false
将打印一个字符串,然后是一个应该为真(在 Expect.true
的情况下)或假(在Expect.false
).