{"id":21010615,"url":"https://github.com/geoffdutton/jasmine-spy-helpers","last_synced_at":"2026-04-22T18:31:24.664Z","repository":{"id":36241952,"uuid":"187267156","full_name":"geoffdutton/jasmine-spy-helpers","owner":"geoffdutton","description":"Updated jasmine spy helpers for less boilerplate code.","archived":false,"fork":false,"pushed_at":"2023-01-06T01:51:03.000Z","size":515,"stargazers_count":0,"open_issues_count":25,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T03:42:20.722Z","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/geoffdutton.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":"2019-05-17T18:57:29.000Z","updated_at":"2021-05-10T17:35:09.000Z","dependencies_parsed_at":"2023-01-17T00:00:29.776Z","dependency_job_id":null,"html_url":"https://github.com/geoffdutton/jasmine-spy-helpers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/geoffdutton/jasmine-spy-helpers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffdutton%2Fjasmine-spy-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffdutton%2Fjasmine-spy-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffdutton%2Fjasmine-spy-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffdutton%2Fjasmine-spy-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geoffdutton","download_url":"https://codeload.github.com/geoffdutton/jasmine-spy-helpers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffdutton%2Fjasmine-spy-helpers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32149383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T17:06:48.269Z","status":"ssl_error","status_checked_at":"2026-04-22T17:06:19.037Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-19T09:21:43.106Z","updated_at":"2026-04-22T18:31:24.645Z","avatar_url":"https://github.com/geoffdutton.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jasmine-spy-helpers\n[![NPM version](http://img.shields.io/npm/v/jasmine-spy-helpers.svg?style=flat-square)](https://www.npmjs.com/package/jasmine-spy-helpers)\n[![Build Status](https://travis-ci.org/geoffdutton/jasmine-spy-helpers.svg?branch=master)](https://travis-ci.org/geoffdutton/jasmine-spy-helpers)\n[![Coverage Status](https://coveralls.io/repos/github/geoffdutton/jasmine-spy-helpers/badge.svg?branch=master)](https://coveralls.io/github/geoffdutton/jasmine-spy-helpers?branch=master)\n\n\njasmine-spy-helpers adds some helper functions to Jasmine.\n\njasmine-spy-helpers is compatible with __Jasmine 2.0+__, but it will track with the current Jasmine version.\n\n## Utils Functions\n\n- `jasmine.spyAll(object)`\n  - Spy all functions of given object.\n  - Spies are configured with `callThrough`\n\n```javascript\nit('should spy all methods', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  jasmine.spyAll(obj);\n\n  expect(obj.method1).not.toHaveBeenCalled();\n  expect(obj.method2).not.toHaveBeenCalled();\n});\n```\n\n- `jasmine.spyIf(function)`\n  - Spy function if and only if function is not already a spy.\n  - Spy is returned.\n\n```javascript\nit('should spy method once', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  jasmine.spyIf(obj, 'method1');\n  jasmine.spyIf(obj, 'method1');\n});\n```\n\n- `jasmine.spyAllExcept(object, [excepts])`\n  - Spy all functions of given object, excepts function names given in array (second arguments).\n  - Spies are configured with `callThrough`\n\n```javascript\nit('should spy selected method', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  jasmine.spyAllExcept(obj, 'method2');\n});\n```\n\n- `jasmine.spyEach(object, [only])`\n  - Spy all functions of given object that are specified in array as second arguments.\n  - Spies are configured with `callThrough`\n\n```javascript\nit('should spy selected method', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    },\n    method3: function() {\n    }\n  };\n\n  jasmine.spyEach(obj, ['method1', 'method2');\n});\n```\n\n- `jasmine.resetAll(object)`\n  - Reset all spy of given object.\n\n```javascript\nit('should reset all methods', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  spyOn(obj, 'method1');\n  spyOn(obj, 'method2');\n\n  obj.method1();\n  obj.method2();\n\n  expect(obj.method1).toHaveBeenCalled();\n  expect(obj.method2).toHaveBeenCalled();\n\n  jasmine.resetAll(obj);\n\n  expect(obj.method1).not.toHaveBeenCalled();\n  expect(obj.method2).not.toHaveBeenCalled();\n});\n```\n\n- `jasmine.resetEach(object, [methods])`\n  - Reset each specified spies of given object.\n\n```javascript\nit('should reset all methods', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  spyOn(obj, 'method1');\n  spyOn(obj, 'method2');\n\n  obj.method1();\n  obj.method2();\n\n  expect(obj.method1).toHaveBeenCalled();\n  expect(obj.method2).toHaveBeenCalled();\n\n  jasmine.resetEach(obj, ['method1']);\n\n  expect(obj.method1).not.toHaveBeenCalled();\n  expect(obj.method2).toHaveBeenCalled();\n});\n```\n\n- `jasmine.resetAllExcept(object, [methods])`\n  - Reset all spies of given object except specified methods.\n\n```javascript\nit('should reset all methods', function() {\n  var obj = {\n    id: 1,\n    method1: function() {\n    },\n    method2: function() {\n    }\n  };\n\n  spyOn(obj, 'method1');\n  spyOn(obj, 'method2');\n\n  obj.method1();\n  obj.method2();\n\n  expect(obj.method1).toHaveBeenCalled();\n  expect(obj.method2).toHaveBeenCalled();\n\n  jasmine.resetAllExcept(obj, ['method1']);\n\n  expect(obj.method1).toHaveBeenCalled();\n  expect(obj.method2).not.toHaveBeenCalled();\n});\n```\n\n## Licence\n\nMIT License (MIT)\n\n## Credits\nA lot of code was borrowed from [jasmine-utils](https://github.com/mjeanroy/jasmine-utils), but I was looking to create just the spy helpers.\n\n## Contributing\n\nOpen to pull requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeoffdutton%2Fjasmine-spy-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeoffdutton%2Fjasmine-spy-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeoffdutton%2Fjasmine-spy-helpers/lists"}