{"id":20432097,"url":"https://github.com/sroettering/ng2-mock","last_synced_at":"2026-04-27T18:03:17.620Z","repository":{"id":143896676,"uuid":"116391360","full_name":"sroettering/ng2-mock","owner":"sroettering","description":"An easy way to mock your Angular stuff","archived":false,"fork":false,"pushed_at":"2018-10-17T07:47:27.000Z","size":53,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T19:05:43.543Z","etag":null,"topics":["angular","mocking"],"latest_commit_sha":null,"homepage":null,"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/sroettering.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":"2018-01-05T14:06:27.000Z","updated_at":"2018-10-17T07:47:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcde3610-4416-435d-8485-5ac90aeae402","html_url":"https://github.com/sroettering/ng2-mock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sroettering/ng2-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroettering%2Fng2-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroettering%2Fng2-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroettering%2Fng2-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroettering%2Fng2-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sroettering","download_url":"https://codeload.github.com/sroettering/ng2-mock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroettering%2Fng2-mock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261348638,"owners_count":23145308,"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":["angular","mocking"],"created_at":"2024-11-15T08:13:53.796Z","updated_at":"2026-04-27T18:03:12.580Z","avatar_url":"https://github.com/sroettering.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version](https://badge.fury.io/js/ng2-mock.svg)](http://badge.fury.io/js/ng2-mock)\n\n# ng2-mock\n\nAn easy way to mock your Angular elements.\n\n_Note_: If you are using Angular \u003c 5 use v0.0.7 of ng2-mock\n_Note_: If you are using Angular \u003c 6 use v0.1.0 of ng2-mock\n\n## Currently Supported Angular Elements\n\n- [x] Component\n- [x] Pipe\n- [x] Directive\n- [x] Service\n- [ ] Guard\n- [ ] Module\n\n## Installation\n\n```\nnpm install --save-dev ng2-mock\n```\n\n## Usage\n\nJust call the `Mock()` function with your desired class(es) and let ng2-mock do the magic.\n\nMock() accepts an arbitrary number of supported angular elements as an argument and returns their mocked versions.\nIf it detects an Injectable class, e.g. Services, as input it mocks the class and returns a provider object \n```typescript\n{ provide: MyInjectableClass, useValue: MockedMyInjectableClass }\n```\nwrapping the mocked element, so you don't have to override the provider yourself.\n\n__Note:__ In order for a mocked service method to return a value other than `undefined` you have to use spies (`Jasmine.spyOn()` for \nexample).\n\n## Example\n```typescript\nimport { Mock } from 'ng2-mock';\n\ndescribe('AppComponent', () =\u003e {\n  let app: AppComponent;\n  let fixture: ComponentFixture\u003cAppComponent\u003e;\n    \n  beforeEach(async(() =\u003e {\n    TestBed.configureTestingModule({\n      declarations: [\n        AppComponent,\n        Mock(MyAComponent),\n        Mock(MyBComponent, MyCComponent, APipe),\n      ],\n      providers: [\n        Mock(MyAService),\n        Mock(MyBService, MyCService, MyDService),  \n      ],\n    }).compileComponents();\n    \n  beforeEach(() =\u003e {\n    fixture = TestBed.createComponent(MapComponent);\n    app = fixture.componentInstance;\n    fixture.detectChanges();\n  });\n    \n  }));\n\n  it('should create the app', () =\u003e {\n    expect(app).toBeTruthy();\n  });\n  \n  it('should call CService.doSomething', () =\u003e {\n      // Spying on a mocked service\n      const cServiceInstance = TestBed.get(MyCService);\n      const spy = spyOn(cServiceInstance, 'doSomething');\n      app.methodWhichCallsCServiceDoSomething();\n      expect(spy).toHaveBeenCalled();\n    });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsroettering%2Fng2-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsroettering%2Fng2-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsroettering%2Fng2-mock/lists"}