Packages

@vitest/expect

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

Your version

2.1.0

12 Sep 2024Where it was published

2.1.9 is the newest release of 2.x.

In short

4 breaking17 new33 fixed

  • breaking

    workspace: Correctly resolve workspace globs and file paths

  • breaking

    workspace: This changes how the custom glob pattern in the workspace config is treated. Any file matching the glob is considered a Vitest config file. Any folder matching the glob pattern is treated as a workspace project and is subject to the regular config resolution (single vitest.config.ts or vite.config.ts inside the folder)

  • breaking

    workspace: For example, projects/* will match anything inside the projects folder. If it's a folder, we try to find the config inside that folder (if there is none, it is still treated as a project with the default config). If it's a file, it will be treated as a Vitest config. projects/**/* previously would assume that you only wanted to have folders as projects, but now it will match every single file insideprojects.

  • breaking

    workspace: This change doesn't affect non-glob usage.

Release note

This release makes another big change to the Browser Mode by introducing locators API:

test('renders blog posts', async () => {
  const screen = page.render(<Blog />)

  await expect.element(screen.getByRole('heading', { name: 'Blog' })).toBeInTheDocument()

  const [firstPost] = screen.getByRole('listitem').all()

  await firstPost.getByRole('button', { name: 'Delete' }).click()

  expect(screen.getByRole('listitem').all()).toHaveLength(3)
})

You can use either vitest-browser-vue, vitest-browser-svelte or vitest-browser-react to render components and make assertions using locators. Locators are also available on the page object from @vitest/browser/context.

Potential Breaking Change

  • breaking

    workspace: Correctly resolve workspace globs and file paths

  • breaking

    workspace: This changes how the custom glob pattern in the workspace config is treated. Any file matching the glob is considered a Vitest config file. Any folder matching the glob pattern is treated as a workspace project and is subject to the regular config resolution (single vitest.config.ts or vite.config.ts inside the folder)

  • breaking

    workspace: For example, projects/* will match anything inside the projects folder. If it's a folder, we try to find the config inside that folder (if there is none, it is still treated as a project with the default config). If it's a file, it will be treated as a Vitest config. projects/**/* previously would assume that you only wanted to have folders as projects, but now it will match every single file insideprojects.

  • breaking

    workspace: This change doesn't affect non-glob usage.

Features

  • api: Make spec into a class instead of a tuple

  • browser: Move page.config to server.config, add more docs

  • browser: Make iframe scalable, improve documentation

  • browser: Introduce built-in locators

  • browser: Support v8 coverage

  • browser: Support userEvent.upload in playwright provider

  • browser: Support --inspect

  • browser: Support --inspect-brk

  • cli: Extend existing list command to output only a list of file names

  • coverage: Add --exclude-after-remap

  • mocker: Introduce @vitest/mocker package, allow { spy: true } instead of a factory

  • vitest: Add "provide" option

  • vitest: Add return type and promisable mockFactory

  • vitest: Add vi.advanceTimersToNextFrame

  • vitest: Allow env to be stubbed to undefined

  • Migrate from fast-glob to tinyglobby

Bug Fixes

  • Correctly resolve nested mocks with index file

  • Don't panic when coverage.reporter is a string

  • Align RawMatcherFn type definition with Jest

  • Cjs build of vite node server

  • Allow inlining vite's cached dependencies

  • Print unexpected error message if peer dependencies have a different version

  • Ignore importer when resolving Vitest

  • expect.getState().testPath always returns correct path

  • UserEvent works consistently between providers

  • browser: Print correct stack trace for unhandled errors

  • browser: Use documentElement as the root for selector

  • browser: Keep querying elements even if locator is created with elementLocator, add pubic @vitest/browser/utils

  • browser: Produce valid config file if preview provider is used

  • browser: Correctly run in-source tests in the browser

  • browser: Exclude missed packages from optimization, print help message

  • browser: Define mocker as a dependency

  • coverage: Warn if vitest and @vitest/* versions don't match

  • coverage: V8 to support source maps with multiple sources

  • coverage: V8 to warn instead of crash when conversion fails

  • coverage: Use project specific vitenode for uncovered files

  • runner: Use performance.now instead of Date.now for duration

  • runner: Async assertion auto await should timeout

  • snapshot: Reject multiple toMatchInlineSnapshot updates at the same location

  • snapshot: Improve inline snapshot inside loop rejection

  • typecheck: Run both runtime and typecheck tests if typecheck.include overlaps with include

  • types: Allow Callbacks Passed to before*/after* to Return Anything

  • ui: Remove "filters" flickering

  • ui: Render project name consistently

  • vite-node: Disable watcher if hmr is disabled

  • vite-node: Fix watch on vite 6

  • vitest: Update json reporter output

  • vitest: Add more type guards for --merge-reports

  • vitest: Always resolve vitest to the root version

  • vitest: Dispose vmForks listeners to avoid memory leak