簡體   English   中英

如何使用“toHaveBeenCalledWith”在 Jasmine 中斷言 boolean

[英]how can I assert boolean in Jasmine using “toHaveBeenCalledWith”

我試圖斷言 function 被調用:

expect(functionA).toHaveBeenCalledWith(xxx, yyyy, true);

我不關心 xxx 和 yyyy 是什么,我只關心最后一個參數是否為真。

如何在 Jasmine 中做到這一點? 我試過了:

expect(functionA).toHaveBeenCalledWith(jasmine.objectContaining(true));

而 true 不是 object。

我也試過:

expect(functionA.calls.mostRecent().args[2]).toMatch(true);

但它給了我錯誤:

Error:<toMatch>:Expected is not a String or a RegExp

我應該如何斷言它? 我是 Jasmine 的新手,謝謝!

假設 xxx 和 yyyy 是字符串,你可以這樣做:

expect(functionA).toHaveBeenCalledWith(jasmine.any(String), jasmine.any(String), true);

另請參閱文檔: 官方文檔

暫無
暫無

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

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