Custom Matchers

Learn how to clean up test code using custom expectation matchers.

We'll cover the following

Jasmine gives us the ability to write our own custom matchers. This allows us to clean up our code, where we keep having to repeat the same expectations. To add a custom matcher, we must do the following two things:

  1. Define an object that specifies the behavior of the custom matcher.

  2. In the beforeEach block of our test suite, we use the addMatchers method to extend the Jasmine functionality with our custom matcher.

Get hands-on with 1200+ tech skills courses.