expect is used with a matcher function to assert something about a value: pass the value your code produces to expect, and the correct value to the matcher. The .not modifier tests the opposite, and .resolves or .rejects unwrap fulfilled or rejected promises so any other matcher can be chained. Use .toBe for primitive values or referential identity — it calls Object.is — but not for floating-point numbers; use .toBeCloseTo there. Use .toEqual for deep equality of object instances, noting it ignores keys with undefined properties, undefined array items, array sparseness, and type mismatch; use .toStrictEqual when those differences matter. Asymmetric matchers such as expect.any(constructor), expect.arrayContaining, expect.objectContaining, and expect.stringMatching make individual fields flexible. expect.assertions(number) and expect.hasAssertions() verify assertions actually ran, expect.extend registers custom matchers, and jest-extended offers community-maintained additions. With TypeScript, explicitly import { expect, jest, test } from '@jest/globals'. Scope: Jest. Reviewed October 4, 2026.
Asserting values with expect matchers
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- jestjs.io
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.