I'm basically trying to mock an external module in the same way for all my vitest tests, and it's surprisingly not trivial. In Jest, I would just create a __mocks__
folder at the root, and it appears vitest is maybe supposed to support this, but I can't get it to work. Anybody figured out this (seemingly very basic) use case?
Tried creating a __mocks__
folder at the root, tried doing a global mock in vite.config.ts. I want to create one mock that works for all tests
__mocks__
folder at the root, but make sure to add vi.mock('module'); in the test file or 2. add a test set up file whih handles your mocks and then add it to your vitest config in the "setupFiles" array vitest.dev/config/#setupfiles. From the docs: ...if you don't call vi.mock, modules are not mocked automatically. To replicate Jest's automocking behaviour, you can call vi.mock for each required module inside setupFiles. – Brae