-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)pr welcome
Description
Describe the bug
When using vi.mock('./SomeClass.ts'); to mock a module that is a class exported as default export class SomeClass {...}, it will have all of its instances to share the same 'mock' attribute in the methods.
And if your code create multiple instances of that SomeClass, it is not possible to check if a method was called from one or the other instance as both will share the mock attribute.
This works fine in Jest, both checks above will be false.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-i4zx4z?file=test%2Fbasic.test.ts
System Info
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Memory: 5.79 GB / 31.91 GB
Binaries:
Node: 18.15.0 - ~\.nvm\versions\node\v18.15.0\bin\node.EXE
npm: 9.5.0 - ~\.nvm\versions\node\v18.15.0\bin\npm.CMD
npmPackages:
@vitejs/plugin-react-swc: 3.4.0 => 3.4.0
@vitest/coverage-v8: 0.34.6 => 0.34.6
vite: 4.4.11 => 4.4.11
vitest: 0.34.6 => 0.34.6Used 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
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)pr welcome