{"id":16537619,"url":"https://github.com/acdcjunior/axios-stubber","last_synced_at":"2025-04-04T20:45:25.661Z","repository":{"id":35042705,"uuid":"199545407","full_name":"acdcjunior/axios-stubber","owner":"acdcjunior","description":"Simplified axios request and response stubbing","archived":false,"fork":false,"pushed_at":"2023-01-08T18:12:10.000Z","size":365,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T04:31:51.587Z","etag":null,"topics":[],"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/acdcjunior.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-30T00:32:27.000Z","updated_at":"2022-05-14T00:01:01.000Z","dependencies_parsed_at":"2023-01-15T12:37:43.065Z","dependency_job_id":null,"html_url":"https://github.com/acdcjunior/axios-stubber","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acdcjunior%2Faxios-stubber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acdcjunior%2Faxios-stubber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acdcjunior%2Faxios-stubber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acdcjunior%2Faxios-stubber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acdcjunior","download_url":"https://codeload.github.com/acdcjunior/axios-stubber/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249601,"owners_count":20908211,"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":[],"created_at":"2024-10-11T18:43:00.640Z","updated_at":"2025-04-04T20:45:25.641Z","avatar_url":"https://github.com/acdcjunior.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# axios-stubber\n\n[![axios-stubber version](https://img.shields.io/npm/v/axios-stubber?color=green)](https://www.npmjs.com/package/axios-stubber)\n\nSimplified axios request and response stubbing.\n\nStubs `axios` globally, making its calls return as specified in stubs files (or objects).\n\n```sh\nnpm i -D axios-stubber\nyarn add --dev axios-stubber\n```\n\n# axiosStubber\n\n```js\nimport axios from 'axios';\nimport axiosStubber from 'axios-stubber';\n\ntest('axios-stubber example', async () =\u003e {\n    axiosStubber(axios, {\n        request: {\n            method: \"GET\",\n            url: \"https://w00t.com\"\n        },\n        response: {\n            status: 201,\n            body: {\n                yes: \"It is\"\n            }\n        }\n    }); // the argument could also be an array, a json file, or js file \n\n    let {data, status} = await axios.get(\"https://w00t.com\");\n\n    expect(data).toStrictEqual({yes: \"It is\"});\n    expect(status).toStrictEqual(201);\n});\n```\n\nTest file:\n\n```js\nconst go = require('./go');\n\nimport axios from 'axios';\nimport axiosStubber from 'axios-stubber';\n\ndescribe('axiosStubber', () =\u003e {\n\n    let axiosMockControl;\n    afterEach(() =\u003e {\n        if (axiosMockControl) axiosMockControl.restore();\n    });\n\n    it('get', async () =\u003e {\n        axiosMockControl = axiosStubber(axios, __dirname + '/stubs/exampleApi.stubs.json');\n\n        let {data} = await axios.get(\"http://master.example.com/info?code=123\");\n        expect(data).toStrictEqual({result: 123456});\n    });\n\n    it('post', async () =\u003e {\n        axiosMockControl = axiosStubber(axios, __dirname + '/stubs/exampleApi.stubs.json');\n\n        let r = await go();\n        expect(r).toStrictEqual({yay: true});\n    });\n\n    it('get', async () =\u003e {\n        axiosMockControl = axiosStubber(axios, [__dirname + '/stubs/exampleApi.stubs.json']);\n\n        let {data} = await axios.get(\"http://master.example.com/info?code=123\");\n        expect(data).toStrictEqual({result: 123456});\n    });\n\n    it('get', async () =\u003e {\n        axiosMockControl = axiosStubber(axios, [\n            {\n                request: {\n                    method: \"GET\",\n                    url: \"https://w00t.com\"\n                },\n                response: {\n                    status: 201,\n                    body: {\n                        yes: \"It is\"\n                    }\n                }\n            }\n        ]);\n\n        let {data, status} = await axios.get(\"https://w00t.com\");\n        expect(data).toStrictEqual({yes: \"It is\"});\n        expect(status).toStrictEqual(201);\n    });\n\n});\n```\n\n\n# axiosStubsRecorder\n\nIntercepts all axios calls and generates a stubs file for later use.\n\n```js\nimport { axiosStubsRecorder } from 'axios-stubber';\n\ntest('t1 - save to new file', async () =\u003e {\n    const axiosMockControl = axiosStubsRecorder(axios, 'my.stubs.json');\n\n    let {data} = await axios.get(\"https://reqres.in/api/users/3\");\n\n    expect(data.data.first_name).toEqual('Emma');\n    expect(data.data.last_name).toEqual('Wong');\n\n    // you can now check that 'my.stubs.json' has all requests and responses recorded\n    \n    axiosMockControl.restore();\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facdcjunior%2Faxios-stubber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facdcjunior%2Faxios-stubber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facdcjunior%2Faxios-stubber/lists"}