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:
-
Define an object that specifies the behavior of the custom matcher.
-
In the
beforeEach
block of our test suite, we use theaddMatchers
method to extend the Jasmine functionality with our custom matcher.
Get hands-on with 1400+ tech skills courses.