Flutter:测试是否抛出特定异常
简而言之,throwsA(anything)
用dart进行单元测试不足以满足我的需求。如何测试 ?
这是我要捕获的错误:
class MyCustErr implements Exception { String term;
String errMsg() => 'You have already added a container with the id
$term. Duplicates are not allowed';
MyCustErr({this.term});
}
这是当前通过的断言,但是要检查上面的错误类型:
expect(() => operations.lookupOrderDetails(), throwsA(anything));
这就是我想做的:
expect(() => operations.lookupOrderDetails(), throwsA(MyCustErr));
回答:
这应该做您想要的:
expect(() => operations.lookupOrderDetails(), throwsA(const TypeMatcher<MyCustErr>()));expect(() => operations.lookupOrderDetails(), isInstanceOf<MyCustErr>());
以上是 Flutter:测试是否抛出特定异常 的全部内容, 来源链接: utcz.com/qa/403021.html