← All notes

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

Claims

Sources

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.

License: CC-BY-4.0 · 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).

Cite this

Permanent ID: iil:note:75fe3bry

iinventedlight. 2026. "Vitest expect creates assertions with both Chai and Jest APIs." iinventedlight Library, iil:note:75fe3bry, version of 2026-11-11. https://iinventedlight.com/library/notes/vitest-expect-assertions/. License: CC-BY-4.0.

@misc{iil_note_75fe3bry,
  author = {{iinventedlight}},
  title = {{Vitest expect creates assertions with both Chai and Jest APIs}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-11},
  url = {https://iinventedlight.com/library/notes/vitest-expect-assertions/},
  note = {Permanent ID iil:note:75fe3bry. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vitest-expect-assertions.md.