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 equality tester, we create a function which takes two arguments. Let's create an equality tester for employees. If two employee objects have same e-mail and name, we will consider them to be equal. So, our function goes as follows:
customEqualityTester...