I am completing a migration from Jasmine 1.3 to 2.0. So far I have refactored most of the code to comply with 2.0's newer syntax. However, a certain kind of tests are still failing.
In short, my test looks like this:
var obj = new CustomCriteria();
spyOn(my, "function");
my.function(obj);
expect(my.function).toHaveBeenCalledWith({ big: "fat object" });
my CustomCriteria
class:
var CustomCriteria = function() {
this.big = "fat object";
};
The test fails with the following:
Expected spy function to have been called with [ Object({ big: "fat object" }) ] but actual calls were [ ({ big: "fat object" }) ].
Note how the expectation has an "Object
" wrapping around it, but the second does not. This test did not fail in < 2.0 of Jasmine, but is now failing after I update Jasmine. How can I fix this?
Update: I tinkered around with creating a new object via new
ing a function
vs. object literal syntax, and it appears that the __proto__
s are different. Perhaps this affects Jasmine's equality comparison?
Prior to version 2, objects are equal if they have the same properties and values (see v1.3.1 code)
From version 2 onward, object constructors are also compared (see v2.0 code).
In your case: CustomCriteria
and {}
do not have the same constructor.
P.S.: The exception message also changed to contain the constructor name in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With