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
- id: C1 claim: expect is used to create assertions. source: S1 evidence: "
expectis used to create assertions."
- id: C2 claim: Vitest ships Chai assertions by default. source: S1 evidence: "Vitest provides
chaiassertions 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.
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
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.},
}
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.