Writing Jasmine tests with custom matchers
Jasmine's built-in matchers are very useful and work well in most scenarios. However, sometimes we need to develop custom matchers to implement specific scenarios. For example, we need to create the custom matchers to override the failure message or to define a new message (or custom error message). Also, a custom matcher can be created when you find a piece of code that tests the same set of properties over and over again across the different specs, and you want to bundle the fragment into a single assertion. By writing your own matcher, you eliminate code duplication and make tests more readable. In other words, by defining your own matchers, you develop a Domain-Specific Language (DSL) to describe the intent of tests in a more readable and expressive way.
To write a Jasmine test using custom matchers, let's assume that the task is to develop an online ordering module for <XYZ> company's website. There are some business rules...