[英]How to test an exception was not thrown with Jest?
Jest 文檔沒有演示一種斷言沒有拋出異常的方法,只有那個。
如果沒有<\/strong>被拋出,我如何斷言?
您始終可以使用.not
方法,如果您的初始條件為假,該方法將有效。 它適用於每個笑話測試:
expect(() => ...error...).not.toThrow(error)
it('function has been fully executed without throwing any errors', () => {
expect(() =>
targetFunctionCall(),
).not.toThrowError();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.