-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
Description
Describe the bug
If you mock a Class with vi.fn(), the mocked class has all static functions removed. Similar to #8850, except that typescript can find the functions but the runtime cannot.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-mjassekr?file=test%2Fbasic.test.ts
class Dog {
public static speak(): string {
return 'Woof!';
}
}
const MockDog = vi.fn( Dog );
console.log( 'Dog.speak()', Dog.speak );
console.log( 'MockDog.speak()', MockDog.speak );Actual Result:
stdout | dogtest.ts
Dog.speak() [Function: speak]
MockDog.speak() undefined
Expected Result:
stdout | dogtest.ts
Dog.speak() [Function: speak]
MockDog.speak() [Function: speak]
System Info
$ npx envinfo --system --npmPackages '{vitest*,@vitest/*,vite,@vitejs/*,playwright,webdriverio}' --binaries --browsers
System:
OS: macOS 26.0.1
CPU: (8) arm64 Apple M1
Memory: 92.83 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.21.0 - /Users/matt/.nvm/versions/node/v22.21.0/bin/node
npm: 10.5.2 - /usr/local/bin/npm
Browsers:
Chrome: 142.0.7444.60
Firefox: 143.0.1
Safari: 26.0.1
npmPackages:
@vitest/coverage-v8: ^3.2.4 => 3.2.4
vitest: ^4.0.7 => 4.0.7Used 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.
Reactions are currently unavailable