{"id":15416577,"url":"https://github.com/remcohaszing/axios-test-instance","last_synced_at":"2025-04-19T14:33:27.267Z","repository":{"id":57188637,"uuid":"216199191","full_name":"remcohaszing/axios-test-instance","owner":"remcohaszing","description":"Test NodeJS backends using Axios","archived":false,"fork":false,"pushed_at":"2023-05-16T08:17:42.000Z","size":1013,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-08T18:52:12.450Z","etag":null,"topics":["axios","express","http","koa","nodejs","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remcohaszing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-19T11:58:32.000Z","updated_at":"2022-12-19T12:51:54.000Z","dependencies_parsed_at":"2024-06-19T00:04:24.440Z","dependency_job_id":"b5e7e882-3c23-4837-bf4b-7e00d53fb394","html_url":"https://github.com/remcohaszing/axios-test-instance","commit_stats":{"total_commits":84,"total_committers":1,"mean_commits":84.0,"dds":0.0,"last_synced_commit":"b66e377caf231a148970784f1d6fba16c8eede8f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Faxios-test-instance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Faxios-test-instance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Faxios-test-instance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Faxios-test-instance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remcohaszing","download_url":"https://codeload.github.com/remcohaszing/axios-test-instance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234444586,"owners_count":18833657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","express","http","koa","nodejs","testing"],"created_at":"2024-10-01T17:12:27.758Z","updated_at":"2025-01-17T23:52:21.405Z","avatar_url":"https://github.com/remcohaszing.png","language":"TypeScript","readme":"# Axios Test Instance\n\n\u003e Test NodeJS backends using Axios\n\n[![build status](https://github.com/remcohaszing/axios-test-instance/workflows/ci/badge.svg)](https://github.com/remcohaszing/axios-test-instance/actions/workflows/ci.yaml)\n[![codecov](https://codecov.io/gh/remcohaszing/axios-test-instance/branch/main/graph/badge.svg)](https://codecov.io/gh/remcohaszing/axios-test-instance)\n[![npm](https://img.shields.io/npm/v/axios-test-instance)](https://www.npmjs.com/package/axios-test-instance)\n[![prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)\n[![jest](https://jestjs.io/img/jest-badge.svg)](https://jestjs.io)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [See also](#see-also)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install axios-test-instance\n```\n\n## Usage\n\n1. Create an Axios test instance by passing your app, which may be a Koa app, an Express app, or an\n   HTTP request handler, to `setTestApp` in a `beforeAll` or `beforeEach` block.\n2. Import `request` and use it in tests.\n\n```js\nimport { request, setTestApp } from 'axios-test-instance'\n\nimport { app } from './app.js'\n\nbeforeAll(async () =\u003e {\n  await setTestApp(app)\n})\n```\n\nThe method above works with Jest, but it might not work with your testing framework. For this use\ncase, a test instance can be created manually using `createInstance`.\n\n```js\nimport { createInstance } from 'axios-test-instance'\n\nimport { app } from './app.js'\n\nlet instance\n\nbeforeAll(async () =\u003e {\n  instance = await createInstance(app)\n})\n\nafterAll(async () =\u003e {\n  await instance.close()\n})\n```\n\nChances are you’re already using an Axios instance in your frontend. In this case, `patchInstance`\ncan be used to patch this instance instead.\n\n```js\nimport { patchInstance } from 'axios-test-instance'\n\nimport { app } from './app.js'\nimport { request } from './request.js'\n\nlet instance\n\nbeforeAll(async () =\u003e {\n  instance = await patchInstance(request, app)\n})\n\nafterAll(async () =\u003e {\n  await instance.close()\n})\n```\n\nNow requests made using this instance, will be redirected to the app under test.\n\n## Examples\n\nFor usages examples, have a look at our test cases:\n\n- [Koa example](__tests__/koa.ts)\n- [Express example](__tests__/express.ts)\n- [Fastify example](__tests__/fastify.ts) (See\n  [#2](https://github.com/remcohaszing/axios-test-instance/issues/2) for limitations)\n- [HTTP callback example](__tests__/callback.ts)\n- [End to end example](__tests__/e2e.ts)\n\n## See also\n\n- [jest-axios-snapshot](https://github.com/remcohaszing/jest-axios-snapshot) asserts axios responses\n  using jest snapshots.\n\n## License\n\n[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremcohaszing%2Faxios-test-instance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremcohaszing%2Faxios-test-instance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremcohaszing%2Faxios-test-instance/lists"}