[英]how does jasmine compare complex objects and arrays
In jasmine, how does comparison helpers such as expect(a).toEqual()
work in the source code? 在jasmine中,
expect(a).toEqual()
等比较助手如何在源代码中工作? Does it check by ducktyping? 它是通过ducktyping检查的吗?
Whenever you are not sure, look into the source code : 每当您不确定时,请查看源代码 :
(taken from Learn to Read the Source, Luke ). (取自学习阅读源,卢克 )。
I won't quote the actual implementation (it's quite big), but here is the underlying util function performing the check. 我不会引用实际的实现(它非常大),但这是执行检查的底层util函数 。
FYI, it is actually adapted from _.isEqual()
and uses stacks to perform deep object and array comparisons. 仅供参考,它实际上是从
_.isEqual()
改编而来,并使用堆栈来执行深层对象和数组比较。
Note that you can extend the jasmine equality check by adding your custom equality testers . 请注意,您可以通过添加自定义相等测试程序来扩展茉莉花相等性检查。
The short answer 简短的回答
toEqual
compares all the properties of both objects and returns true if the corresponding values are equal. toEqual
比较两个对象的所有属性,如果相应的值相等则返回true。
The long answer 答案很长
You can follow the trail of toEqual
in the source code and eventually land here in the eq
method which gives the gritty details...(and I quote the source: 'lovingly adapted from isEqual in Underscore ') 您可以在源代码中跟踪
toEqual
的跟踪,并最终落在eq
方法中 ,该方法提供了详细信息......(我引用了源代码:' 在下划线中精心改编为isEqual ')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.