Packages

@vitest/expect

5.0.5 · 15 Oct 2026MIT151.9M / weekRepositoryHomepagenpmAtom feed

Your version

4.0.0

major22 Oct 2025Where it was published

4.1.12 is the newest release of 4.x.

In short

29 breaking1 removed32 new12 faster69 fixed1 internal

  • breaking

    Remove 'basic' reporter

  • breaking

    Simplify default exclude pattern

  • breaking

    Remove deprecated getSourceMap

  • breaking

    Replace deprecated ErrorWithDiff with TestError

  • breaking

    Remove UserConfig type in favor of ViteUserConfig

  • breaking

    Remove deprecated coverage options in favor of vitest/node exports

  • breaking

    Remove deprecated internal helpers and environment exports

  • breaking

    Remove deprecated typecheck and runner types

Release note

Vitest 4.0 is out!

To stay updated, read our blog post and check the migration guide.

Breaking Changes

  • breaking

    Remove 'basic' reporter

  • breaking

    Simplify default exclude pattern

  • breaking

    Remove deprecated getSourceMap

  • breaking

    Replace deprecated ErrorWithDiff with TestError

  • breaking

    Remove UserConfig type in favor of ViteUserConfig

  • breaking

    Remove deprecated coverage options in favor of vitest/node exports

  • breaking

    Remove deprecated internal helpers and environment exports

  • breaking

    Remove deprecated typecheck and runner types

  • breaking

    Remove Node types from the main entry point, use vitest/node instead

  • breaking

    Remove support for Vite 5

  • breaking

    Remove deprecated types

  • breaking

    Remove deprecated environmentMatchGlobs and poolMatchGlobs

  • breaking

    Remove deprecated workspace option in favor of projects

  • breaking

    Ignore --standalone when CLI filename filter is used

  • breaking

    Use module-runner instead of vite-node

  • breaking

    Rewrite spying implementation to make module mocking more intuitive

  • breaking

    Remove deprecated APIs

  • breaking

    Remove minWorkers and set it automatically to 0 in non watch mode

  • breaking

    Verbose reporter prints tests in a list, introduce tree reporter

  • breaking

    Include shadow root contents in pretty-format output

  • breaking

    Remove deprecated order from test() API

  • breaking

    Rewrite pools without tinypool

  • breaking

    browser: Require a provider factory instead of a string

  • breaking

    expect: Pass current equality testers to asymmetric matcher

  • breaking

    projects: Allow only files that have "vitest.config" or "vite.config" in the name

  • breaking

    reporter: Remove deprecated APIs

  • breaking

    runner: Set mode to todo if no function is passed down to test or describe

  • breaking

    snapshot: Fail test with obsolete snapshot on CI

  • breaking

    spy: Support spying on classes

Features

  • Provide entity to onConsoleLog

  • Add onUnhandledError callback

  • Add spy option to vi.mockObject

  • Don't use vite-node in coverage packages

  • Clickable dashboard numbers

  • Display test "path" when filtering

  • Introduce separate packages for browser mode providers

  • Add hooks with type-safe extra context to TestAPI

  • Support expect.assert for type narrowing

  • Add displayAnnotations option to github-options

  • Add schema validation matchers

  • Add a way to dump transformed content

  • api: Expose experimental_parseSpecifications

  • api: Expose Vitest watcher

  • api: Add enableCoverage and disableCoverage methods

  • api: Add getGlobalTestNamePattern method

  • api: Add relativeModuleId to TestModule

  • api: Add getSeed method

  • browser: Support toBeInViewport utility method to assert element is in viewport or not

  • browser: Add qwik to the vitest init cli command

  • browser: Introduce toMatchScreenshot for Visual Regression Testing

  • browser: Add trackUnhandledErrors option

  • browser: Support iframe locator with playwright provider

  • browser: Add length property to locators, toHaveLength now accepts locators

  • browser: Support playwright tracing

  • browser: Expose options on BrowserProviderOption

  • browser: Support --inspect option in webdriverio

  • browser: Support custom screenshot comparison algorithms

  • coverage: autoUpdate to support percentage formatting

  • expect: Support toBeNullable expect function to check provided value is nullish

  • mocker: Add automocker entry

Bug Fixes

  • Allow overriding globals in types

  • Remove unused dependencies

  • Distribute test files to shards more evenly

  • Use suite's timeout when test.extend

  • Support snapshot with no object key sorting

  • Annotation location always points to the test file

  • Add --changed flag support to vitest list command

  • Prevent rpc timeout on slow thread blocking synchronous methods

  • Forbid setting environment to browser

  • Invalidate modules in all module graphs when the file is changed

  • Screenshot masks with Playwright provider

  • Configure oxc instead of esbuild on rolldown-vite

  • Make sure test errors always have stacks property in Node.js context

  • Support import.meta.resolve on Vite 7

  • Show the assertion error first when expect.poll assertion fails

  • Override fake timers when useFakeTimers is called multiple times

  • Custom expect messages for expect.extend matchers

  • Process sourcemaps for stack traces from globalSetup files

  • Resolve performance issue when throwing errors with stackTraceLimit = 0

  • Avoid recursively applying $ and % formatting to test.for/each title

  • Replace wildcard exports "./*" with specific files in vitest package

  • Don't publish unused d.ts files

  • Remove loupe dependencies from optimizeDeps.include for browser mode

  • Update engines field to drop Node 18 support

  • Correctly inherit test options on extended tests

  • Update @types/node peer deps

  • Re-export CDP Session directly from playwright

  • Disable trackUnhandledErrors if inspector is enabled

  • base option doesn't crash vitest

  • browser: Run in-source tests only when the file itsels is a test file

  • browser: locator.element() returns HTMLElement or SVGElement

  • browser: Don't import from vite directly

  • browser: Update expect.element type to match the implementation

  • browser: Throw an error if iframe is not accessible anymore

  • browser: Stop creating unnecessary directories when taking screenshots

  • browser: Always define commands

  • browser: Exclude deprecated context import from optimization

  • browser: Allow importing BrowserCommand if no browser package is installed

  • browser: Define an export for browser/utils

  • browser: Allow service workers to mock the network in chromium without breaking vi.mock

  • browser: Support sync not.toBeInTheDocument()

  • core: Fix objectContaining expect utility to have more compatibility to jest's one

  • coverage: Include files based on --project filter

  • coverage: Prevent encoding filenames of uncovered files

  • coverage: Handle query param based transforms correctly

  • coverage: Enforce order of vitest:coverage-transform plugin

  • coverage: V8 to ignore Vite's generated cjs import helpers

  • coverage: Keep only strings in coverage.exclude

  • deps: Update all non-major dependencies

  • deps: Update all non-major dependencies - in #8328

  • deps: Update all non-major dependencies - in #8348

  • deps: Update all non-major dependencies

  • deps: Update all non-major dependencies - in #8550

  • jsdom: Override globals that Fetch API relies on

  • jsdom: Support AbortSignal API

  • mocker: Fix regexpHoistable to allow whitespace before parentheses

  • module-runner: Resolve resolvedSources correctly

  • module-runner: Support getBuiltins

  • pool: Properly reuse the vm pool

  • reporter: Invisible CLI menus when vitest --standalone

  • rolldown-vite: Properly disable minifier in the browser client

  • runner: Don't bundle runner with utils

  • spy: Fix spyOn types with optional method

  • spy: Can respy on an exported method

  • spy: Don't fail when spying on static getters

  • types: Ensure Chai declaration merge works with TS-Go

  • types: Allow returning a promise from defineConfig

  • ui: Keep the same tab open when clicking on different tests

  • removed

    utils: Remove ast export

  • vitest: Override config.include option with config.browser.instances.include option if it is specified

  • wdio: Wait for the driver to be properly closed

  • wdio: Properly construct the shadow root selector if there are multiple elements

Performance

  • Avoid spawning extra workers if no tests will run there

  • Don't set process.title

  • Remove chai as a direct dependency, keep it in @vitest/expect

  • Reduce the amount of dynamic imports

  • Use ES2022 language features

  • Delay populating node-globals

  • Get workerId from a global object

  • Replace startsWith with strict equality

  • Reduce the number of unused imports

  • Use experimental meta.resolve flag instead of a custom loader

  • Create only one fetcher per project

  • pool: Resolve all environments first