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

Get Jasmine Cookbook 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.