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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.