Mock axios requests for testing. v0.4.0 is the latest stable release (infrequent updates). Allows you to install a mock adapter into axios, intercept requests, and respond with custom data. Unlike alternatives like axios-mock-adapter, moxios provides a higher-level API with `moxios.wait()` and `moxios.requests.mostRecent()`, making it easier to write integration tests that simulate asynchronous request handling. Requires axios (peer dependency). Limited to browser-like environments (uses XMLHttpRequest).
npm install moxiosNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup using install/uninstall, waiting for a request, and responding with custom data.
Use moxios.uninstall() after each test and ensure no other XHR mocks are active.
Use moxios.wait() and manually assert on requests.
Chain .then() after respondWith() or use async/await.
Avoid fake timers or use moxios.requests.mostRecent() synchronously if possible.
Call moxios.install() in beforeEach or before the relevant test.
import moxios from 'moxios' (not import { moxios } from 'moxios').Ensure axios is using the same adapter (moxios installs). Check that the request URL matches.