testing.shouldError() 函数
testing.shouldError() 调用一个捕获任何错误并检查错误是否与预期值匹配的函数。
函数类型签名
(fn: () => A, want: regexp) => stream[{v: string}]
有关更多信息,请参见 Function type signatures。
参数
函数
(必填) 调用的函数。
想要
(必填) 用于匹配预期错误的正则表达式。
示例
测试死亡函数错误
import "testing"
testing.shouldError(fn: () => die(msg: "error message"), want: /error message/)