Vitest 5: Tests That Passed Silently Now Fail
Vitest 5 shipped on September 3, 2026. One of its changes reads like a footnote in the migration guide, yet it touches the thing a test suite exists to protect: the verdict itself. Any asynchronous assertion that is not preceded by await now fails the test, instead of passing with a warning in the logs.
The problem: a green result that means nothing
A failing test gives you information. A passing test that checked nothing gives you false confidence — and that is far more expensive.
In earlier versions, forgetting await on expect(...).resolves, rejects or toMatchFileSnapshot meant Vitest auto-awaited the promise and emitted a warning. Warnings in CI dissolve into thousands of log lines, so the test stayed green while the real check never ran inside the test's boundaries. Teams then make decisions on imaginary coverage: the pipeline is green, the deploy goes out, and the defect surfaces in front of users.
What changed
Vitest 5 settles it — the warning became an explicit failure.
// Before: passes even if the promise rejects — nobody notices
test('createUser returns an id', () => {
expect(createUser({ name: 'Sara' })).resolves.toMatchObject({ id: 1 })
})
// Vitest 5: fails loudly, because the assertion was never awaited
test('createUser returns an id', async () => {
await expect(createUser({ name: 'Sara' })).resolves.toMatchObject({ id: 1 })
})This upgrade is not cosmetic. The first run after updating usually exposes tests that have been green for months while asserting nothing — which is exactly what a test runner should do: contradict you early rather than flatter you for a long time.
vi.when: per-argument behavior
The release's second face is vi.when, which replaces hand-written switch statements inside mockImplementation whenever a spy needs a different value per input:
import { vi, test, expect } from 'vitest'
const fetchRate = vi.fn()
vi.when(fetchRate)
.calledWith('SAR')
.thenReturn(3.75)
.calledWith('USD')
.thenReturn(1)
test('converts using per-currency rates', () => {
expect(fetchRate('SAR')).toBe(3.75)
expect(fetchRate('USD')).toBe(1)
})The API supports deep equality and asymmetric matchers such as expect.any(), and ships thenThrow, thenResolve and thenReject alongside their Once variants, plus an onUnmatched option that decides what happens when unexpected arguments arrive. The practical gain: mocks get described rather than programmed, so less code exists that tests nothing.
Trace view inside Browser Mode
Browser Mode gains a built-in trace view that replays a test step by step with DOM snapshots, available in the browser UI and in the HTML reporter. The experience is close to the Playwright Trace Viewer, without extra tooling in the dependency tree. When a locator fails, the error output now prints the ARIA tree — a small addition that saves real time when debugging UI tests.
Performance gains vary with the setup, with the largest wins in the vm pools, in Browser Mode, and in large isolated suites.
Edges worth checking before upgrading
- Minimum versions are now Node.js 22.12 and Vite 6.4; anything older is unsupported.
clearMocksdefaults totrue, so mock history is cleared between tests. Any test implicitly relying on accumulated calls will break.- Benchmarks were rewritten:
benchis no longer a top-level import but a fixture insidetest(), andbench.skip/only/todoplus the--compareflag are gone. - Calling
vi.mock()outside module scope — insidedescribeortest— now throws instead of being silently hoisted. - Inline projects inherit root configuration by default (
extendsistrue). Convenient in a monorepo, but it changes settings you may have assumed were isolated. testNamePatternnow uses' > 'as the separator between levels, so review any CI filtering.
Takeaway
What distinguishes this release is that it reduces the number of places where a suite can lie: a forgotten assertion is now a failure, a vague mock is now an explicit description, and a browser failure is now replayable. Tests are not written to be green — they are written to be honest. On a related note about catching regressions, we previously covered statistical tests inside the Node.js histogram for CI.
Primary source: the official Vitest 5 announcement and the migration guide.