Vitest v4.1 Update: Tags, aroundEach Hooks, Chai Assertions & 40+ Features
Key Changes
Vitest v4.1, released on March 12, 2026, is one of the largest Vitest releases to date — over 40 new features spanning test organization, assertion APIs, browser testing, coverage, and developer experience. Several experimental features have been stabilized.
Test Tags
Tests can now be tagged for selective execution:
test('checkout flow', { tags: ['@critical', '@e2e'] }, () => {
// ...
});
// Run only critical tests
// vitest --tags @critical
Tags work across test, describe, and bench. This enables smart CI strategies — run @smoke tests on every push, @full suite on merge.
aroundEach and aroundAll Hooks
New lifecycle hooks that wrap test execution:
test.aroundEach(async (run) => {
await db.beginTransaction();
await run();
await db.rollbackTransaction();
});
This pattern replaces verbose beforeEach/afterEach pairs and guarantees cleanup runs even when tests throw. aroundAll does the same for suite-level setup.
Chai-Style Assertions
Vitest now supports chai assertion syntax alongside the existing API:
expect(result).to.be.an('array').that.has.lengthOf(3);
This lowers the migration barrier for teams coming from Mocha/Chai.
Async Leak Detection
The new --detect-async-leaks flag identifies tests that leave unresolved promises or timers:
vitest --detect-async-leaks
Async leaks are a common source of flaky tests and memory issues in CI. This flag helps teams track them down systematically.
Coverage for Changed Files Only
The coverage.changed option reports coverage only for files modified since the last commit:
export default defineConfig({
test: {
coverage: {
changed: true,
},
},
});
This dramatically speeds up coverage reporting in large codebases and makes PR coverage checks more focused.
Browser Testing Enhancements
Significant Playwright integration improvements:
- Persistent context support — maintain browser state across tests
page.mark()API — enhance Playwright trace with custom markerslaunchOptionswithconnectOptions— full control over browser launch- BlazeDiff replaces pixelmatch — faster visual comparison
userEvent.wheelAPI — scroll simulation in browser testsfindElementwith strict mode — stricter element resolution in WebDriverIO/preview
More Highlights
mockThrowandmockThrowOnce— cleaner error mockingvi.mockoutside top-level warning — catches common mistakes- Static test collection for
vitest list— faster test discovery without execution test.meta— attach metadata to individual tests- Type inference with
test.extend— improved fixture typing - Vite 8 beta support — forward-compatible with next Vite major
- GitHub Actions run summary — rich test summaries in GHA
- Agent reporter — reduced token usage when running through AI agents
- UI improvements — individual test/suite run, project filtering, duration sorting, slow test filter
Impact for QA Teams
Vitest v4.1 transforms how teams organize and run tests at scale. Tags enable smart CI pipelines without separate config files. aroundEach eliminates boilerplate setup/teardown patterns. Async leak detection tackles one of the hardest debugging problems in JavaScript testing. The Playwright browser enhancements position Vitest as a serious contender for full-stack testing — unit, component, and browser in one tool. For teams comparing test frameworks, see our Jest vs Mocha comparison.
