Advanced Matchers
Explore how to use advanced Jasmine matchers including toMatch with regular expressions to write expressive and precise expectations in Angular unit tests. Learn to validate string formats such as currency and improve your testing flexibility.
We'll cover the following...
Jasmine offers a number of matchers that let us write expressive expectations.
The toMatch method
There are two ways to check whether a string value contains a specified string.
-
We can call the
toMatchmethod with our search string. -
We can call the
toContainmethod with our search string.
Take a look at the code example below. These two expectations are equivalent:
We can also use the toMatch method to let us match a
/ symbol, but we do not use quotation marks. In the second example, we use /i, which is ...