Packages

@vitest/mocker

5.1.0 · 2 Nov 2026MIT190.8M / 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

2 new12 fixed

Security

2 advisories affect 2.1.0; 4.1.12 fixes them

Release note

The section about @vitest/mocker of a note shared by several packages.

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.

Features

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

  • 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

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

  • ui: Remove "filters" flickering

  • ui: Render project name consistently

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.