{"id":20727271,"url":"https://github.com/john-doherty/fetch-reply-with","last_synced_at":"2025-04-23T18:51:28.280Z","repository":{"id":57150839,"uuid":"101621321","full_name":"john-doherty/fetch-reply-with","owner":"john-doherty","description":"Unit test fetch requests with ease","archived":false,"fork":false,"pushed_at":"2023-02-08T04:57:22.000Z","size":126,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T12:58:10.021Z","etag":null,"topics":["fetch","fetch-api","mock","nodejs","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/john-doherty.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-28T08:26:51.000Z","updated_at":"2023-02-14T09:34:38.000Z","dependencies_parsed_at":"2024-06-19T06:15:49.383Z","dependency_job_id":"12e6021b-9906-46a7-bc98-fad730e13820","html_url":"https://github.com/john-doherty/fetch-reply-with","commit_stats":{"total_commits":51,"total_committers":4,"mean_commits":12.75,"dds":"0.33333333333333337","last_synced_commit":"33c28d027c56c4c98bdaec505954ff41fb9cfe80"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Ffetch-reply-with","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Ffetch-reply-with/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Ffetch-reply-with/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Ffetch-reply-with/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/john-doherty","download_url":"https://codeload.github.com/john-doherty/fetch-reply-with/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250496272,"owners_count":21440227,"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":["fetch","fetch-api","mock","nodejs","unit-testing"],"created_at":"2024-11-17T04:29:49.442Z","updated_at":"2025-04-23T18:51:28.259Z","avatar_url":"https://github.com/john-doherty.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-reply-with\n\n[![npm version](https://badge.fury.io/js/fetch-reply-with.svg)](https://www.npmjs.com/package/fetch-reply-with)\n[![Tests](https://github.com/john-doherty/fetch-reply-with/actions/workflows/ci.yml/badge.svg)](https://github.com/john-doherty/fetch-reply-with/actions/workflows/ci.yml)\n\n\nSimplifies unit tests by intercepting [fetch](https://developers.google.com/web/updates/2015/03/introduction-to-fetch#fetch) requests and returning [mocked](https://en.wikipedia.org/wiki/Mock_object) responses.\n\n## Install\n\n```bash\nnpm install --save-dev fetch-reply-with\n```\n\n## Usage\n\n```js\nrequire('fetch-reply-with'); // \u003c- `fetch` is now globally available\n\n// intercept GET http://orcascan.com and reply with...\nfetch('http://orcascan.com', {\n\n    // regular fetch option\n    method: 'GET',\n\n    // add reply for this fetch\n    replyWith: {\n        status: 200,\n        body: 'Barcode Scanner app',\n        headers: {\n            'Content-Type': 'text/html'\n        },\n        delay: 500 // miliseconds to wait before responding (default = 0)\n    }\n});\n\n// execute fetch request\nfetch('http://orcascan.com').then(function(res){\n    return res.text();\n})\n.then(function(text){\n    // text === `Barcode Scanner app`\n});\n```\n\nCouple of things to note:\n* Requests not setup with `replyWith` are executed as normal\n* A `replyWith` can be modified by redefining the `replyWith`\n\n## Unit Tests\n\nThe project includes unit tests, to run the tests:\n\n1. Checkout `git clone https://github.com/john-doherty/fetch-reply-with`\n2. Navigate into project folder `cd fetch-reply-with`\n3. Install dependencies `npm install`\n4. Run the tests `npm test`\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -m 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :)\n\n## Star the repo\n\nIf you find this useful please star the repo, it helps us prioritize fixes :raised_hands:\n\n## History\n\nFor change-log, check [releases](https://github.com/john-doherty/fetch-reply-with/releases).\n\n## License\n\nLicensed under [MIT License](LICENSE) \u0026copy; [John Doherty](https://twitter.com/mrjohndoherty)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Ffetch-reply-with","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn-doherty%2Ffetch-reply-with","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Ffetch-reply-with/lists"}