9. Advanced Jest Matchers Flashcards
What is a Matcher also known as?
An assertion or an expectation.
What does a Matcher represent?
A claim that a value will be equal (or not) to something.
What happens if a Matcher’s claim is not validated?
An error is thrown, letting Jest know that the test has failed.
What happens if an error is thrown inside a test?
The test fails.
What is the not
matcher?
A special matcher that reverses an assertion. It works with any assertion and turns it into its opposite — if assertion without not
would pass, assertion with not
will fail, and vice versa.
What do the toBe
and the toEqual
Matchers do?
Verify that two values are equivalent.
What is the difference between the toBe
and the toEqual
Matchers?
Two arrays with matching elements are equal (toEqual), but not identical (toBe).
What is the toBeEqual
Matcher?
A number Matcher that is similar to toEqual
, but assertion still passes if numbers are close but not equal.
What is the toBeEqual
Matcher useful for?
Assertions involving floating point numbers.
What kind of matchers are toContain
and toHaveLength
?
Array matchers that verify the contents and size of a collection.