{"id":20665397,"url":"https://github.com/rohit1901/mockable","last_synced_at":"2026-06-28T19:31:23.824Z","repository":{"id":189494323,"uuid":"680783688","full_name":"rohit1901/mockable","owner":"rohit1901","description":"Mockable automates the mock generation process while maintaining type safety and ease of use. #library","archived":false,"fork":false,"pushed_at":"2023-09-05T10:56:47.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T11:34:07.590Z","etag":null,"topics":["ast","generator","mocks","testing","typescript"],"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/rohit1901.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2023-08-20T11:49:38.000Z","updated_at":"2024-07-09T07:42:33.000Z","dependencies_parsed_at":"2024-11-16T19:30:58.191Z","dependency_job_id":"0d226deb-243e-4f20-b7ea-23e4aef59b5f","html_url":"https://github.com/rohit1901/mockable","commit_stats":null,"previous_names":["rohit1901/mockable"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rohit1901/mockable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit1901%2Fmockable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit1901%2Fmockable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit1901%2Fmockable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit1901%2Fmockable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohit1901","download_url":"https://codeload.github.com/rohit1901/mockable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit1901%2Fmockable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34901959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ast","generator","mocks","testing","typescript"],"created_at":"2024-11-16T19:30:41.875Z","updated_at":"2026-06-28T19:31:23.802Z","avatar_url":"https://github.com/rohit1901.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mockable: Automated Mocking for Unit Testing\n![Typescript](https://shields.io/badge/TypeScript-3178C6?logo=TypeScript\u0026logoColor=FFF\u0026style=flat-square)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThe `mockable` library simplifies unit testing by automating the generation of mock implementations for TypeScript classes and interfaces. With `mockable`, you can quickly create mock objects that adhere to the type definitions of your original code, reducing the need for manual mock creation and maintenance.\n\n## Installation\n\n```bash\nnpm install mockable --save-dev\n```\n\n## Usage\n\n### 1. Annotate Classes or Interfaces\n\nUse the `@Mockable` decorator to indicate which classes or interfaces you want to mock. This will trigger the automated mock generation process.\n\n```typescript\nimport { Mockable } from 'mockable';\n\n@Mockable\nclass UserService {\n  getUser(id: number): Promise\u003cUser\u003e {\n    // Actual implementation fetching user from a server\n  }\n}\n```\n\n### 2. Import and Use Mocks in Tests\n\nIn your test files, import the generated mock implementations and use them in your tests. The mock implementations will match the methods and properties of the original class/interface.\n\n```typescript\nimport { MockUserService } from 'mockable';\n\n// Use the mock in your tests\njest.mock('UserService', () =\u003e MockUserService);\n\n// Example test using the mock\ntest('should return a user', async () =\u003e {\n  MockUserService.getUser.mockResolvedValue({ id: 1, name: 'John' });\n\n  const user = await someFunctionThatUsesUserService();\n\n  expect(user.name).toBe('John');\n});\n```\n\n### 3. Customize Mock Behavior\n\nYou can customize the behavior of the mock methods using Jest's mocking capabilities.\n\n```typescript\nMockUserService.getUser.mockResolvedValue({ id: 1, name: 'Custom Name' });\n```\n\n## Features\n\n- Automatic generation of mock implementations for annotated classes/interfaces.\n- Retains type safety by inferring method signatures and return types from the original code.\n- Customizable mock behavior using Jest's mocking features.\n- Reduces boilerplate and speeds up unit test writing and maintenance.\n\n## Examples\n\nFor more detailed examples and advanced usage, please refer to the [Examples](./src/examples) directory in this repository.\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohit1901%2Fmockable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohit1901%2Fmockable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohit1901%2Fmockable/lists"}