Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Creating a matcher for equals-method #167

Phoscur opened this Issue · 2 comments

3 participants


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


As the standard matcher from jasmine doesn't check for this method, I wrote my own matcher:

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:

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.


How are you calling your toBeEqualTo method? It sounds like there's some things not getting defined here.

You do realize you have a typo for actual? This may be what is causing your problem, if this code is directly copy-pasted from your implementation. We set this.actual, not this.acutal.


Also note that Jasmine allows for custom equality testers. This is very poorly (read: NOT) documented for 1.x. But for 2.0 we're making it more explicit.

Look at the matchers_redo branch to see how you can add your own equality tester to the equals work. This will then get used everywhere that equality is tested (e.g., toContain, toHaveBeenCalledWith).


@infews infews closed this
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.