問題描述
Jasmine 內置了匹配器 toBe
和 toEqual代碼>.如果我有這樣的對象:
Jasmine has built-in matchers toBe
and toEqual
. If I have an object like this:
function Money(amount, currency){
this.amount = amount;
this.currency = currency;
this.sum = function (money){
return new Money(200, "USD");
}
}
并嘗試比較 new Money(200, "USD")
和 sum 的結果,這些內置匹配器將無法按預期工作.我已經設法實現了基于自定義 equals
方法的變通方法 和自定義匹配器,但它似乎很有效.
and try to compare new Money(200, "USD")
and the result of sum, these built-in matchers will not work as expected. I have managed to implement a work-around based on a custom equals
method and custom matcher, but it just seems to much work.
在 Jasmine 中比較對象的標準方法是什么?
What is the standard way to compare objects in Jasmine?
推薦答案
我一直在尋找相同的東西,并找到了一種無需任何自定義代碼或匹配器的現有方法.使用 toEqual()
.
I was looking for the same thing and found an existing way to do so without any custom code or matchers. Use toEqual()
.
這篇關于檢查 Jasmine 中的對象相等性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!