vitest-mocking
Installation
SKILL.md
Vitest Mocking
Test Double Types
| Type | Purpose | Changes Implementation? |
|---|---|---|
| Spy | Record calls, verify interactions | No (uses real code) |
| Mock | Replace module entirely | Yes |
| Stub | Return canned responses | Yes |
| Fake | Working but simplified impl | Yes |
Decision Guide
Use spy when: Verifying a function was called correctly while keeping real behavior
const fetchSpy = vi.spyOn(globalThis, "fetch");
await doSomething();
expect(fetchSpy).toHaveBeenCalledWith("https://api.example.com");