[英]Using object types with Jasmine's toHaveBeenCalledWith method
[英]Jasmine tohaveBeenCalledWith() Object comparison
我的 jasmine 測試目前對我來說在expect(mySpy).toHaveBeenCalledWith(myArray)
上失敗了,我不確定如何解釋以下消息:
預期的間諜 mySpy 已被調用 [ Object({ type: Function, name: 'foo', value: [[ Object({type: Function, name: 'one' value: '1' }), Object({type :Function,名稱:'兩個',值:'2'}),...]] })]
但實際調用是 [ Object({ type: Function, name: 'foo', value: [[ Object, Object, ... ] })
請注意,預期的 object 具有value
屬性的完整類型和值,但在實際調用中,Jasmine 只發現它們是對象,沒有關於它們的內部值的詳細信息。 我知道 jasmine 很難比較函數,您需要傳遞對兩者的相同引用,我就是,但是為什么 Jasmine 沒有提供有關實際調用的全部細節,以及為什么僅僅因為它們是對象而失敗?
這很奇怪,我這樣處理這個問題:
// get a handle on the arguments that the most recent call the spy was invoked with
const arguments = mySpy.calls.mostRecent().args;
console.log({ arguments });
expect(arguments[0]).toBe(....); // assert the first argument to be of ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.