Skip to content


.toEqual fails for objects with the same members but of different types #598

adrianton3 opened this Issue · 5 comments

3 participants

it("should tell me what's the difference between these 2", function () {
  function A() { this.a = 10; }
  function B() { this.a = 10; }
  expect(new A()).toEqual(new B());

fails, but it does not say why - it only states: Expected { a : 10 } to equal { a : 10 }. which is instead true.


Which version of Jasmine are you running?



Jasmine member

Jasmines equality does take into account the constructor used to create the object, which seems like the right thing to do, but the pretty printer ignores the constructor when printing an object. Would having the pretty printer print help? This would probably mean that your error reads more like:

Expected A({ a : 10 }) to equal B({ a : 10 })

It would help to at least tell that the constructors are different or to not look like it's contradicting itself.
The name can still lead to bizarre reports if you're using anonymous constructors (for whatever reason) or worse: if you're using different constructors but with the same name. Also, the name property is not yet standardized.

Jasmine member

I made a story in our tracker to fix the failure message under this circumstance (, but we'd be happy to review a pull request for this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.