O'Reilly logo

Test-Driven JavaScript Development by Harmeet Singh, Hetal Prajapati, Ravi Kumar Gupta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required