mhevery/jasmine-node — Issue #109: Creating a matcher for equals-method
Author: Phoscur
Created: 2011-12-28 01:12:49+00:00
State: open

I don't know if you do this, but I build my ValueObjects with an equals-method. So I can define my own conditions to the equality of two objects. These are to be compared by
> obj1.equals(obj2)
As the standard matcher from jasmine doesn't check for this method, I wrote my own matcher:
```javascript
toBeEqualTo: function(expected) {
return this.acutal.equals(expected);
}
```
>TypeError: Cannot call method 'equals' of undefined
Really? I was quite sure about the rest of the code, so I reversed it:
```javascript
toBeEqualTo: function(expected) {
return expected.equals(this.acutal);
}
```
> Error: Expected { method : Function, equals : Function, ... } to be equal to { method : Function, equals : Function, ... } at ... bla
Huh? So now I'm confused. Are these objects undefined or equal but not equal?

Also, my objects have a toString/toJSON method, I like those to be used if I see them printed out.