Skip to content

Loading…

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

Closed
adrianton3 opened this Issue · 5 comments

3 participants

@adrianton3
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.

@infews

Which version of Jasmine are you running?

@adrianton3

2.0.0

@slackersoft
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 object.constructor.name help? This would probably mean that your error reads more like:

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

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.

@slackersoft
Jasmine member

I made a story in our tracker to fix the failure message under this circumstance (https://www.pivotaltracker.com/story/show/81228592), 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.