testing.shouldErrorWithCode() 函数
testing.shouldErrorWithCode()
调用一个函数,该函数捕获任何错误并检查错误是否与预期值匹配。
函数类型签名
(code: uint, fn: () => A, want: regexp) => stream[{match: bool, code: uint, _diff: string}]
有关更多信息,请参阅 函数类型签名。
参数
fn
(必需) 要调用的函数。
want
(必需) 用于匹配预期错误的正则表达式。
code
(必需) 要预期的 Flux 错误代码
示例
测试 die 函数错误
import "testing"
testing.shouldErrorWithCode(fn: () => die(msg: "error message"), want: /error message/, code: 3)
此页面是否对您有帮助?
感谢您的反馈!