簡體   English   中英

"如何測試 Jest 沒有拋出異常?"

[英]How to test an exception was not thrown with Jest?

Jest 文檔沒有演示一種斷言沒有拋出異常的方法,只有那個。

如果沒有<\/strong>被拋出,我如何斷言?

您始終可以使用.not方法,如果您的初始條件為假,該方法將有效。 它適用於每個笑話測試:

expect(() => ...error...).not.toThrow(error)

https://facebook.github.io/jest/docs/en/expect.html#not

it('function has been fully executed without throwing any errors', () => {
        expect(() =>
          targetFunctionCall(),
        ).not.toThrowError();
      });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM