Book Image

Jasmine Cookbook

By : Munish Kumar
Book Image

Jasmine Cookbook

By: Munish Kumar

Overview of this book

Table of Contents (16 chapters)
Jasmine Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing a Jasmine test using a custom equality tester function


You can customize how Jasmine determines whether two objects are equal by defining your own custom equality tester. A custom equality tester is a function, which takes two arguments. This function returns either true or false based on the arguments. Also, if it is unable to compare the argument values, then the custom equality tester function will return undefined.

In this recipe, you will learn how to compare the equality of two objects using such custom equality tester functions.

Let's consider a scenario where the equality of two strings should be decided using a custom equality tester function.

"As a JavaScript developer, I want to develop a mechanism to check the equality of two strings so that I can compare and categorize objects."

  • Scenario-1: Two strings should be equal if the first word of both strings is Packt

How to do it...

You need to perform the following steps:

  1. First, you need to create a spec file (custom_equality_spec...