Jest Matchers: Asserting Values in Your Tests

Jest matchers are assertion functions that check if a value meets a condition. You use them with `expect()` to verify function outputs, object properties, or promise states.
Jest matchers are assertion functions that validate if your code's output meets conditions. Think of `expect(value).toBe(expected)` as asking, "Is the value my code produced what I think it should be?". You use them to check primitives (`.toBe`), objects (`.toEqual`), or promise states (`.resolves`). The footgun: always put your code's output in `expect()` and the correct value in the matcher. Swapping them makes failure messages confusing and unhelpful.
Read the original → jestjs.io
- #jest
- #testing
- #javascript
- #assertions
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.