{"id":17914398,"url":"https://github.com/lawvs/mocat","last_synced_at":"2025-03-23T23:30:49.294Z","repository":{"id":37997712,"uuid":"190438079","full_name":"lawvs/mocat","owner":"lawvs","description":"🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.","archived":false,"fork":false,"pushed_at":"2025-03-08T18:29:42.000Z","size":3656,"stargazers_count":29,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T05:09:40.112Z","etag":null,"topics":["mock","mock-server","mocking-framework","testing-library","testing-tools","web-development"],"latest_commit_sha":null,"homepage":"https://lawvs.github.io/mocat/#/user/login","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/lawvs.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":"2019-06-05T17:22:47.000Z","updated_at":"2025-03-08T18:29:45.000Z","dependencies_parsed_at":"2022-08-26T21:57:21.123Z","dependency_job_id":"221a48f2-7c9e-4dfc-8e57-c630fc89a8ec","html_url":"https://github.com/lawvs/mocat","commit_stats":{"total_commits":286,"total_committers":4,"mean_commits":71.5,"dds":0.1748251748251748,"last_synced_commit":"23a11e7a9cac50cbc0b25226ef8b29e61e8a3dd4"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fmocat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fmocat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fmocat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lawvs%2Fmocat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lawvs","download_url":"https://codeload.github.com/lawvs/mocat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186448,"owners_count":20574551,"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":["mock","mock-server","mocking-framework","testing-library","testing-tools","web-development"],"created_at":"2024-10-28T19:58:09.678Z","updated_at":"2025-03-23T23:30:48.675Z","avatar_url":"https://github.com/lawvs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mocat\n\n![CI](https://github.com/lawvs/mocat/workflows/CI/badge.svg)\n[![npm](https://img.shields.io/npm/v/mocat)](https://www.npmjs.com/package/mocat)\n\nMocat is a development toolbar for mocking. It allows you to interactively develop and test network requests. This library is inspired by [cypress](https://github.com/cypress-io/cypress).\n\n![demo](https://user-images.githubusercontent.com/18554747/100751183-5ab4c800-342a-11eb-9172-5df6d1198f06.gif)\n\n## Installation\n\nTo install and save in your package.json dev dependencies, run:\n\n```sh\n# With npm\nnpm install --save-dev mocat\n\n# Or with yarn\nyarn add --dev mocat\n\n# Or with pnpm\npnpm add --save-dev mocat\n```\n\n## Usage\n\n```ts\n// mock.ts\nimport { create } from 'mocat'\n\nconst app = create()\n\napp.mockRoute({\n  name: 'login api',\n  // Specify the URL to match\n  url: '/api/login',\n  // Create scenarios\n  scenarios: [\n    {\n      name: 'login success',\n      response: {\n        username: 'Alice',\n        msg: 'ok',\n      },\n    },\n    {\n      name: 'login fail',\n      desc: 'username or password incorrect',\n      // The HTTP status code to send.\n      status: 400,\n      // HTTP headers to accompany the response.\n      headers: { 'Content-Type': 'application/json' },\n      // Serve a static string/JSON object as the response body.\n      response: {\n        msg: 'username or password incorrect',\n      },\n    },\n  ],\n})\n```\n\nThen load it from the application entry:\n\n```ts\n// main.ts\nimport { App } from './App'\n\n// Load React\nReactDOM.render(\u003cApp /\u003e, document.getElementById('app'))\n// Or Vue\ncreateApp(App).mount('#app')\n\nif (process.env.NODE_ENV !== 'production') {\n  await import('./mock')\n}\n```\n\n## API\n\n### MockRoute\n\n```ts\nexport interface MockRoute {\n  /**\n   * The name of API.\n   */\n  name?: string\n  desc?: string\n  /**\n   * Match against the full request URL.\n   * If a string is passed, it will be used as a substring match,\n   * not an equality match.\n   */\n  url: string | RegExp | ((url: string) =\u003e boolean)\n  /**\n   * Match against the request's HTTP method.\n   * All methods are matched by default.\n   */\n  method?:\n    | 'GET'\n    | 'POST'\n    | 'OPTIONS'\n    | 'PUT'\n    | 'DELETE'\n    | 'HEAD'\n    | 'TRACE'\n    | 'CONNECT'\n  scenarios?: NetworkScenario[]\n}\n```\n\n### NetworkScenario\n\n```ts\nexport interface NetworkScenario {\n  /**\n   * The name of scenario.\n   */\n  name: string\n  /**\n   * The description of scenario.\n   */\n  desc?: string\n  /**\n   * The HTTP status code to send.\n   * @default 200\n   */\n  status?: number\n  /**\n   * HTTP headers to accompany the response.\n   * @default {}\n   */\n  headers?: Record\u003cstring, string\u003e\n  /**\n   * Serve a static string/JSON object as the response body.\n   */\n  response?: ConstructorParameters\u003ctypeof Response\u003e[0] | Record\u003cstring, any\u003e\n  error?: any\n}\n```\n\n## Other similar projects\n\n- [Mock](https://github.com/nuysoft/Mock)\n- [data-mocks](https://github.com/ovotech/data-mocks)\n- [xhr-mock](https://github.com/jameslnewell/xhr-mock)\n- [fetch-mock](https://github.com/wheresrhys/fetch-mock)\n- [cypress](https://github.com/cypress-io/cypress)\n- [nise](https://github.com/sinonjs/nise)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawvs%2Fmocat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flawvs%2Fmocat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flawvs%2Fmocat/lists"}