Lightweight, synchronous Axios mock for Vitest testing framework. Current stable version is 0.1.0. Provides a simple API (mockResponse, mockError, lastReqGet, etc.) to simulate Axios requests synchronously in unit tests, making test logic easier to read and write. Key differentiators include synchronous promise resolution (no need to await or use microtasks) and full Vitest spy integration. Requires manual setup of a Vitest module mock in __mocks__/axios.js. Comparatively, alternatives like msw or nock are more feature-rich but typically asynchronous and heavier.
npm install vitest-mock-axiosNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Set up Vitest mock for Axios, use mockResponse to resolve a pending request synchronously.
Create file in __mocks__ directory as described in installation docs.
Ensure test code does not rely on microtask ordering; use mockResponse directly after triggering the request.
Fork source code to replace vi.fn() with spies from other frameworks.
For advanced cancellation logic, consider using a more comprehensive mock library.
Add `vi.mock('axios', () => import('vitest-mock-axios'));` before using axios in test.Ensure factory returns the default export: `vi.mock('axios', () => import('vitest-mock-axios'));`