---
source: https://iinventedlight.com/library/notes/vitest-expect-assertions.md
title: "Vitest expect creates assertions with both Chai and Jest APIs"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (vitest-dev/vitest docs and source); prose restates cited source lines in own words"
license_family: vitest-mit
attribution: "Summary by iinventedlight (AI-assisted). Sources: Vitest docs and Vitest source (vitest-dev/vitest), MIT. Notices: Vitest documentation and source (vitest-dev/vitest): Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors; MIT (https://raw.githubusercontent.com/vitest-dev/vitest/main/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-11
status: published
approved_by: "Cole Withington, 2026-11-11 17:50 PT, Librarian chat widget t44s275: \"Yes, publish all 8 gap drafts\""
approved_by: "Cole Withington, 2026-11-11 17:59 PT, Engineer chat widget t716s3194: \"Yes, publish all 8 gap notes live\""
checked_on: 2026-11-11
as_of: 2026-11-11
confidence: medium
untested: "No Vitest project was run for this note; only the fetched documentation and source files were read."
category: coding-references
topic_area: "code-web: Vitest expect assertions"
tags: [vitest, expect, chai, assertions]
client: Librarian
sources:
  - id: S1
    title: "expect"
    publisher: Vitest docs
    url: https://vitest.dev/api/expect
    accessed: 2026-11-11
    license: "MIT"
  - id: S2
    title: "JestChaiExpect matcher plugin"
    publisher: Vitest source
    url: https://github.com/vitest-dev/vitest/blob/main/packages/expect/src/jest-expect.ts
    accessed: 2026-11-11
    license: "MIT"
---
# Vitest expect creates assertions with both Chai and Jest APIs

**Answer:** `expect` is used to create assertions. Vitest ships Chai assertions by default and Jest-compatible assertions on top of Chai. You can write `expect(input).to.equal(2)` or `expect(input).toBe(2)`. Unlike Jest, Vitest also accepts a message as the second argument of `expect`; if the assertion fails, that message is the error text.

## Types and extras

Since Vitest 4.1, spy and mock checks also have Chai-style forms such as `expect(spy).to.have.been.called()`, alongside Jest-style `toHaveBeenCalled()`. `expect` does not test TypeScript types by itself; use `expectTypeOf` or `assertType` for that. `expect.assert` re-exports Chai's `assert` API, which can narrow types in a way the `to*` matchers do not.

## The matcher plugin in source

`JestChaiExpect` is a `ChaiPlugin`. It uses addMethod on the Assertion prototype and on the matchers object.

## See also

- [vitest-test-runner](https://iinventedlight.com/library/notes/vitest-test-runner/)
- [vitest-mocking](https://iinventedlight.com/library/notes/vitest-mocking/)

## Claims

- id: C1
  claim: expect is used to create assertions.
  source: S1
  evidence: "`expect` is used to create assertions."

- id: C2
  claim: Vitest ships Chai assertions by default.
  source: S1
  evidence: "Vitest provides `chai` assertions by default"

- id: C3
  claim: Jest-style expect matchers are a Chai plugin named JestChaiExpect.
  source: S2
  evidence: "export const JestChaiExpect: ChaiPlugin = (chai, utils) => {"

- id: C4
  claim: Those matchers are added on chai.Assertion.prototype.
  source: S2
  evidence: "utils.addMethod(chai.Assertion.prototype, n, softWrapper)"

## Sources

- [S1] expect. Vitest docs. https://vitest.dev/api/expect . License: MIT. Accessed 2026-11-11.

- [S2] JestChaiExpect matcher plugin. Vitest source. https://github.com/vitest-dev/vitest/blob/main/packages/expect/src/jest-expect.ts . License: MIT. Accessed 2026-11-11.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Vitest documentation and source (vitest-dev/vitest): Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors; MIT (https://raw.githubusercontent.com/vitest-dev/vitest/main/LICENSE). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
