Axios Test Instance is a Node.js library designed to simplify the testing of backend applications by enabling in-memory HTTP requests using the familiar Axios API. It allows developers to test Express, Koa, Fastify, or raw Node.js HTTP handlers without initiating actual network calls, significantly accelerating integration test suites. The current stable version is 8.0.0, and the package maintains a release cadence tied to major updates of its core dependency, Axios, and Node.js LTS release cycles. Its primary strength lies in providing a convenient abstraction over backend server testing, offering methods like `setTestApp` for Jest/Mocha-style global setup, `createInstance` for fine-grained control over test instances, and `patchInstance` to redirect requests from existing Axios configurations. This approach ensures robust testing while maintaining development velocity and adhering to modern JavaScript module standards.
npm install axios-test-instanceVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up an Express application, create an `axios-test-instance`, and use it to make in-memory HTTP requests within a test suite (e.g., Jest).
Upgrade your Node.js runtime to version 16 or later.
Remove manual `form-data` construction if it was used explicitly with `axios-test-instance`. Rely on standard Axios `FormData` behavior or pass plain objects for `application/x-www-form-urlencoded`.
Ensure your project's Axios dependency is compatible with Axios 1.x, or upgrade Axios in your project.
Migrate your test files to use ES Module `import` syntax. If your project is CommonJS, consider transpiling or using dynamic `import()`.
If your tests depend on redirects, explicitly configure Axios to follow them, e.g., by passing `maxRedirects: 5` in your Axios config object for requests.
Upgrade your Node.js runtime to version 14 or later for `v6.x` and `v7.x`, or Node.js 16+ for `v8.x`.
Convert your test files to ES Modules using `import` statements, or ensure your `package.json` has `"type": "module"` if using `.js` files with ESM in a hybrid project.
Ensure `setTestApp` or `createInstance` is properly `await`ed in an asynchronous setup hook (like `beforeAll` or `beforeEach`) before any tests attempt to use the Axios instance.
If you expect redirects, configure the Axios instance to follow them by setting `maxRedirects` in the request config, e.g., `await instance.get('/old-path', { maxRedirects: 5 });`.