Creating a custom equality tester

Sometimes, you may want to compare two values or objects in your way. By defining a custom equality tester, you can modify how Jasmine determines if two values are equal or not.

Whenever an expectation needs to check for equality, custom equality tester will first be used. It would return true or false if it knows how to compare; otherwise, undefined will be returned. If undefined is returned, then only Jasmine's default equality testers will be used.

Let's modify employee.js once more to add setter getter for the e-mail so that we can use in our custom equality tester:

Employee.prototype.setEmail = function(email){
  this.email = email;
}
Employee.prototype.getEmail = function(){
  return this.email;
}

To create a custom ...

Get Test-Driven JavaScript Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.