{"id":13834705,"url":"https://github.com/Typescript-TDD/jest-ts-auto-mock","last_synced_at":"2025-07-10T07:30:53.046Z","repository":{"id":39042549,"uuid":"173917833","full_name":"Typescript-TDD/jest-ts-auto-mock","owner":"Typescript-TDD","description":"Jest test utility with automatic mock creation for interfaces and classes","archived":false,"fork":false,"pushed_at":"2024-09-09T05:07:35.000Z","size":894,"stargazers_count":170,"open_issues_count":13,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-02T16:43:13.295Z","etag":null,"topics":["fake","jest-mock","mock","mock-interface","mock-typescript","testing","typescript-transformer"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Typescript-TDD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-03-05T09:38:52.000Z","updated_at":"2025-06-25T16:33:31.000Z","dependencies_parsed_at":"2024-01-15T18:55:30.143Z","dependency_job_id":"d520f9c4-4057-4db0-8a92-f42c57a98d6a","html_url":"https://github.com/Typescript-TDD/jest-ts-auto-mock","commit_stats":{"total_commits":83,"total_committers":8,"mean_commits":10.375,"dds":0.1807228915662651,"last_synced_commit":"86ee32ab597d143eaba68a1ed8f132a23719bc33"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Typescript-TDD/jest-ts-auto-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Typescript-TDD%2Fjest-ts-auto-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Typescript-TDD%2Fjest-ts-auto-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Typescript-TDD%2Fjest-ts-auto-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Typescript-TDD%2Fjest-ts-auto-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Typescript-TDD","download_url":"https://codeload.github.com/Typescript-TDD/jest-ts-auto-mock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Typescript-TDD%2Fjest-ts-auto-mock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263499201,"owners_count":23476022,"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":["fake","jest-mock","mock","mock-interface","mock-typescript","testing","typescript-transformer"],"created_at":"2024-08-04T14:00:51.246Z","updated_at":"2025-07-10T07:30:52.603Z","avatar_url":"https://github.com/Typescript-TDD.png","language":"TypeScript","funding_links":[],"categories":["Transformers","TypeScript"],"sub_categories":["Testing"],"readme":"# Jest Ts Auto Mock\n\n[![Actions Status](https://github.com/Typescript-TDD/jest-ts-auto-mock/workflows/Master/badge.svg)](https://github.com/Typescript-TDD/jest-ts-auto-mock/actions) \n\n\n\nThis is a library that extend [ts-auto-mock](https://github.com/Typescript-TDD/ts-auto-mock/) to be used with jest\n\nThe intention of the library is to automatically assign jest mock to functions giving you type safety\n\n## Requirements\n\ntypescript@^3.2.2\u003cbr\u003e\nts-jest@\u003e=24 \u003c27\n## Installation\n\n- A Transformer needs to be provided at compile time.\nWe need to tell ts-jest to use ttypescript that allow us to use a transformer.\n### IMPORTANT:\n- set \"cacheBetweenTests\" as false\n- Add the transformer to your ts config \n    ```ts   \n    {\n      \"compilerOptions\": {\n        ...\n        \"plugins\": [\n          { \"transform\": \"ts-auto-mock/transformer\", \"cacheBetweenTests\": false }\n        ]\n      }\n    }\n    ```\n    \n    - Enable ttypescript into the ts-jest configuration\n    ```ts              \n       ...\n       \"globals\": {\n          \"ts-jest\": {\n            \"compiler\": \"ttypescript\"\n          }\n        }\n    ```\n\n- provide jest-ts-auto-mock config before your test\n```ts\n\"jest\": {\n    ...\n    \"setupFiles\": [\n      \"\u003crootDir\u003e/config.ts\"\n    ]\n   ...\n  },\n```\n\n- config file\n```ts\nimport 'jest-ts-auto-mock'\n\n```\n\n## Examples\n[ts-jest-ttypesctipt](examples/ts-jest-ttypescript)\n\n## Usage\n1) create an interface\n```ts\ninterface Interface {\n    methodToMock: () =\u003e string\n}\n```\n2) create a mock\n```ts\nconst mock: Interface = createMock\u003cInterface\u003e();\n```\n3) get the method mock \n\nYou can get the method spy in 2 different ways\n\nThrough method\n```ts\nimport { On, method } from \"ts-auto-mock/extension\";\nconst mockMethod: Jest.Mock = On(mock).get(method(mock =\u003e mock.methodToMock));\n```\n\nThrough string\n```ts\nimport { On, method } from \"ts-auto-mock/extension\";\nconst mockMethod: Jest.Mock = On(mock).get(method('methodToMock'));\n```\n4) trigger the method\n```ts\nsomeMethodThatWillTriggerInterfaceA();\nexpect(mockMethod).toHaveBeenCalled();\n```\n\n## Authors\n\n* [**Vittorio Guerriero**](https://github.com/uittorio)\n* [**Giulio Caprino**](https://github.com/pmyl)\n\n## License\n\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTypescript-TDD%2Fjest-ts-auto-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTypescript-TDD%2Fjest-ts-auto-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTypescript-TDD%2Fjest-ts-auto-mock/lists"}