-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
Describe the bug
After upgrading Vitest from 3.1.1 to 3.2.4, tests that rely on top-level vi.spyOn + vi.clearAllMocks() start failing.
This setup worked in 3.1.1. After upgrading, call-count assertions consistently fail, implying the spy stops collecting calls once clearAllMocks runs. There’s no mention of this behavioral change in the release notes.
Need some help clarifying the expected behavior and best practices.
Reproduction
const funcSpy = vi.spyOn(queries, 'getXXX')defined at module scope.beforeEach(() => vi.clearAllMocks())- Tests that assert
expect(funcSpy).toHaveBeenCalledTimes(1)or.toHaveBeenValledWith(...)start fail. Calls not tracked. - However, the mocked return values from
funcSpy.mockReturnedValueOncestill work as expected for each test case.
System Info
System:
OS: macOS 26.1
CPU: (10) arm64 Apple M1 Pro
Memory: 76.73 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - /Users/simengli/.nvm/versions/node/v22.14.0/bin/node
npm: 10.9.2 - /Users/simengli/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.18.2 - /Users/simengli/Library/pnpm/pnpm
Browsers:
Chrome: 142.0.7444.176
Safari: 26.1
npmPackages:
vitest: ^3.2.4 => 3.2.4Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.