{"id":13781629,"url":"https://github.com/thinkjs/think-mock","last_synced_at":"2025-04-10T19:37:11.232Z","repository":{"id":47418882,"uuid":"88480924","full_name":"thinkjs/think-mock","owner":"thinkjs","description":"Mock for Thinkjs","archived":false,"fork":false,"pushed_at":"2022-12-06T17:27:47.000Z","size":1035,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-18T14:55:07.628Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/thinkjs.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":"2017-04-17T06:57:29.000Z","updated_at":"2021-09-01T05:53:41.000Z","dependencies_parsed_at":"2023-01-24T10:30:46.127Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-mock","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"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-08-03T18:01:27.822Z","updated_at":"2025-04-10T19:37:11.209Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","readme":"# think-mock\n\nMock data for ThinkJS3.\n\n## Precondition\n\nthink-mock need Babel support! For:\n  - @babel/plugin-proposal-class-properties\n  - @babel/plugin-proposal-decorators\n  \nis used!Replace them with corresponding plugin if babel6 is used in your project!\n\n1. Open Babel transform (Both development or production enviroment)\n2. Add plugin to babel config\n\n## How to Use\n\n1. Add extend support \n\n```js\n// think.ROOT_PATH/src/config/extend.js \nconst mock = require('think-mock');\n\nmodule.exports = [\n  mock(think.app),\n];\n\n```\n\n2. Config mock path, or use default\n```js\n  // config.js\n  mock: path.join(think.ROOT_PATH, 'mock'), // default\n```\n\n3. Create mock file\n\n```js\n  // think.ROOT_PATH/mock/user/index.js\n  module.exports = {\n    mock: 'This is mock data.'\n  }\n```\n\n4. Add mock to action or method\n\n```js\n// controller/user.js\nconst { mock } = think.Controller.prototype;\nmodule.exports = class extends think.Controller {\n  @mock\n  indexAction() {\n    // mockFile think.ROOT_PATH/mock/user/index.js\n    return this.json({ data: 'This is real data.' });\n  }\n\n  @mock getUserInfo() {\n    // mockFile think.ROOT_PATH/mock/user/getUserInfo.js\n  }\n}\n\n// service/sms.js\nconst { mock } = think.Service.prototype;\nmodule.exports = class extends think.Service {\n  @mock\n  sendMessage() {\n    // mockFile think.ROOT_PATH/mock/service/sms/sendMessage.js\n    return { data: 'This is real data.' };\n  }\n};\n\n```\n\n## Production\n\nMock auto close when you are not at devlepment enviroment. \n\nYou don't need remove decorator `mock`, but is better if you do. \n","funding_links":[],"categories":["Extends"],"sub_categories":["websocket"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-mock/lists"}