Ściśle równe (lub ===
) oznacza, że porównujesz dokładnie takie same obiekt do siebie:
var myObj = {
testProperty: 'testValue'
};
var anotherReference = myObj;
expect(myObj).to.equal(anotherReference); // The same object, only referenced by another variable
expect(myObj).to.not.equal({testProperty: 'testValue'}); // Even though it has the same property and value, it is not exactly the same object
Głęboko Równe z drugiej strony oznacza, że każdy nieruchomość porównywanego obiekty (i możliwe obiekty głęboko połączone) mają tę samą wartość. Więc:
var myObject = {
testProperty: 'testValue',
deepObj: {
deepTestProperty: 'deepTestValue'
}
}
var anotherObject = {
testProperty: 'testValue',
deepObj: {
deepTestProperty: 'deepTestValue'
}
}
var myOtherReference = myObject;
expect(myObject).to.eql(anotherObject); // is true as all properties are the same, even the inner object (deep) one
expect(myObject).to.eql(myOtherReference) // is still also true for the same reason
Możliwy duplikat [? Jaka jest różnica między równy ?, eql ?, === i ==] (http://stackoverflow.com/questions/7156955/whats-the-difference- między-równym-eql-i) – 8protons