O'Reilly logo

Jasmine Cookbook by Munish Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required