{"id":13661188,"url":"https://github.com/otbe/emock","last_synced_at":"2025-04-12T01:17:27.404Z","repository":{"id":57224696,"uuid":"58868788","full_name":"otbe/emock","owner":"otbe","description":"smart mocks for expect","archived":false,"fork":false,"pushed_at":"2017-08-02T18:00:27.000Z","size":119,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T20:51:16.053Z","etag":null,"topics":[],"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/otbe.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":"2016-05-15T15:22:06.000Z","updated_at":"2018-08-28T14:43:13.000Z","dependencies_parsed_at":"2022-09-04T07:41:23.021Z","dependency_job_id":null,"html_url":"https://github.com/otbe/emock","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Femock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Femock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Femock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Femock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otbe","download_url":"https://codeload.github.com/otbe/emock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119401,"owners_count":21050754,"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-02T05:01:30.793Z","updated_at":"2025-04-12T01:17:27.371Z","avatar_url":"https://github.com/otbe.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# emock\n[![Build Status](https://travis-ci.org/otbe/emock.svg?branch=master)](https://travis-ci.org/otbe/emock)\n\n*emock* automatically generates mocks from your classes. The entire public API will be mocked. It is especially designed\nto use in conjunction with ES6 classes (but not exclusive). Internally it uses [expect](https://github.com/mjackson/expect) spies.\nIt has full TypeScript support and was developed for it!\n\n## Install\n\n```npm i emock --save-dev```\n\n## Usage\nIt is as simple as:\n\n```javascript\nimport { Mock, expectExtensions } from 'emock';\nimport expect, { extend } from 'expect';\n\nextend(expectExtensions);\n\nclass MyService {\n  echo (s: string): string {\n    return s;\n  }\n}\n\ndescribe('Usage', () =\u003e {\n  it('should show me usage', () =\u003e {\n    let m: Mock\u003cMyService\u003e = Mock.of(MyService);\n\n    let service: MyService = m.mock;\n\n    console.log(service.echo('name')); // -\u003e undefined\n\n    // lets add some spy logic\n    m.spyOn(x =\u003e x.echo('Foo')).andReturn('Bar'); // note: x is from type MyService so will get full code completion! :)\n\n    console.log(service.echo('name')); // -\u003e Bar\n\n    // Was echo called?\n    expect(service.echo).toHaveBeenCalled();\n\n    // Was echo called with 'name'?\n    expect(service.echo).toHaveBeenCalledWith('name');\n\n    // Why I have added 'Foo' to the spyOn call? Because we could do the following:\n    (\u003cany\u003eexpect(service.echo)).toHaveBeenCalledWithSignature();\n\n    // the last expect will fail, but why? We have recorded a call signature with m.spyOn(x =\u003e x.echo('Foo'))\n    // That means, if echo is called it should be called with one parameter 'Foo'\n    // toHaveBeenCalledWithSignature() verifies that for us\n  });\n});\n```\nSee tests for more examples. :)\n\n## Matchers\nLike I said before ```m.spyOn(x =\u003e x.echo('Foo'));``` records a call signature, but you don't have to use explicit values\nlike in the example above. You can use some matchers from the ```It``` package. For example:\n\n```javascript\nm.spyOn(x =\u003e x.echo(It.isString()));\n\nm.mock.echo('test');\n(\u003cany\u003eexpect(m.mock.echo)).toHaveBeenCalledWithSignature(); // passes\n\nm.mock.echo('test2');\n(\u003cany\u003eexpect(m.mock.echo)).toHaveBeenCalledWithSignature(); // passes\n\nm.mock.echo(\u003cany\u003e5);\n(\u003cany\u003eexpect(m.mock.echo)).toHaveBeenCalledWithSignature(); // fails with 5 is not a string\n\n```\n\n## Dependencies\n*emock* itself has no dependencies, but some peerDependencies.\n\n* [expect](https://github.com/mjackson/expect) (because *emock* relies on it)\n* [is-equal](https://www.npmjs.com/package/is-equal) (comes with expect)\n\nYou will need some polyfills for your environment if there is no support for used features:\n\n* [Reflect API](https://www.npmjs.com/package/reflect-metadata) with metadata support\n* ```Symbol``` polyfill (comes with babel-polyfill for example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Femock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotbe%2Femock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Femock/lists"}