Using Common Matchers

Learn about matchers, the tool at the center of Jest's testing ease.

What are matchers?

A matcher is what facilitates the assertion portion of a test. It states what we are asserting to be true, ultimately determining the passing or failing of the test.

Jest’s expect function provides a number of these as an out-of-the-box feature. All these are called by simply chaining them onto expect, as shown below:

expect(2 + 2).toEqual(4);

Types of matchers

The matcher library is robust, offering lots of flexibility. Most matchers fall into one of the following categories: ...