{"id":19220419,"url":"https://github.com/louisbrunner/sinon-spy-utils","last_synced_at":"2026-05-15T11:32:43.731Z","repository":{"id":19022447,"uuid":"85850063","full_name":"LouisBrunner/sinon-spy-utils","owner":"LouisBrunner","description":"A collection of util functions to make your life easier when using Sinon.js","archived":false,"fork":false,"pushed_at":"2023-10-18T07:47:09.000Z","size":3028,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T19:43:14.624Z","etag":null,"topics":["js","npm","sinon","tdd","utils"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sinon-spy-utils","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/LouisBrunner.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":"2017-03-22T16:17:12.000Z","updated_at":"2024-06-11T21:11:08.667Z","dependencies_parsed_at":"2023-01-13T20:08:03.955Z","dependency_job_id":"85f23548-1e3e-45e6-8a56-dbf2aa99a23a","html_url":"https://github.com/LouisBrunner/sinon-spy-utils","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.4285714285714286,"last_synced_commit":"bbd2fa79b8d784066c619445431842e539dd1048"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fsinon-spy-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fsinon-spy-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fsinon-spy-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LouisBrunner%2Fsinon-spy-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LouisBrunner","download_url":"https://codeload.github.com/LouisBrunner/sinon-spy-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240293497,"owners_count":19778528,"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":["js","npm","sinon","tdd","utils"],"created_at":"2024-11-09T14:35:05.524Z","updated_at":"2026-05-15T11:32:43.653Z","avatar_url":"https://github.com/LouisBrunner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sinon-spy-utils [![NPM Version][npm-image]][npm-url] ![Build Status][ci-image] [![Coverage Status][coveralls-image]][coveralls-url] [![dependencies Status][deps-image]][deps-url] [![devDependencies Status][deps-dev-image]][deps-dev-url]\n\nThis package is a collection of util functions to make your life easier when using [Sinon.js](http://sinonjs.org).\nAt the moment, it contains *3* functions: `Mock` (creating fake objects), `SpyAndDo` (scoped spy) and `StubAndDo` (scoped stub).\n\n\n## Installation\n\n### Node Installation\n\n```sh\nnpm install sinon-spy-utils\n```\n\nYou can then `SpyUtils = require('sinon-spy-utils')` or `import { Mock } from 'sinon-spy-utils'`.\n\n### Browser Installation\n\nUse the minified UMD build in the `dist` folder: [here](dist/sinon-spy-utils.min.js).\nIt exports a global `window.SinonSpyUtils` when imported as a `\u003cscript\u003e` tag.\n\n\n## Usage\n\nEvery code snippet will be presented in 3 different styles: Node.js `require`, Node.js `import` and Browser Javascript (with required HTML `\u003cscript\u003e`s).\n\n### Mock\n\nThis function creates a mock object containing functions corresponding to the provided names.\n\n - *require*:\n```js\n  var Mock = require('sinon-spy-utils').Mock;\n  ...\n  var fakeUser = Mock('getName', 'getAvatar', 'getAge');\n```\n\n - *import*:\n```js\n  import { Mock } from 'sinon-spy-utils';\n  ...\n  const fakeUser = Mock('getName', 'getAvatar', 'getAge');\n```\n\n - *browser*:\n```js\n  \u003cscript src=\"sinon.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"sinon-spy-utils.min.js\"\u003e\u003c/script\u003e\n  ...\n  var fakeUser = SinonSpyUtils.Mock('getName', 'getAvatar', 'getAge');\n```\n\n### SpyAndDo\n\nThis function will spy the listed functions of the provided object and call the provided function. The spied functions will be restored whatever happens.\n\n - *require*:\n```js\n  var SpyAndDo = require('sinon-spy-utils').SpyAndDo;\n  ...\n  SpyAndDo(console, 'error', 'log', function (spies) {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n - *import*:\n```js\n  import { SpyAndDo } from 'sinon-spy-utils';\n  ...\n  SpyAndDo(console, 'error', 'log', (spies) =\u003e {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n - *browser*:\n```js\n  \u003cscript src=\"sinon.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"sinon-spy-utils.min.js\"\u003e\u003c/script\u003e\n  ...\n  SinonSpyUtils.SpyAndDo(console, 'error', 'log', function (spies) {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n\n### StubAndDo\n\nThis function will stub the listed functions of the provided object and call the provided function. The stubbed functions will be restored whatever happens.\n\n - *require*:\n```js\n  var StubAndDo = require('sinon-spy-utils').StubAndDo;\n  ...\n  StubAndDo(console, 'error', 'log', function (spies) {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n - *import*:\n```js\n  import { StubAndDo } from 'sinon-spy-utils';\n  ...\n  StubAndDo(console, 'error', 'log', (spies) =\u003e {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n - *browser*:\n```js\n  \u003cscript src=\"sinon.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"sinon-spy-utils.min.js\"\u003e\u003c/script\u003e\n  ...\n  SinonSpyUtils.StubAndDo(console, 'error', 'log', function (spies) {\n    functionThatCallsConsoleLog(); // your function\n    expect(spies.log).to.have.been.called; // your test (here using sinon + chai style)\n  });\n```\n\n\n## License\n\nMIT, Copyright (c) 2017-2020 Louis Brunner\n\n\n\n[npm-image]: https://img.shields.io/npm/v/sinon-spy-utils.svg\n[npm-url]: https://npmjs.org/package/sinon-spy-utils\n[ci-image]: https://github.com/LouisBrunner/sinon-spy-utils/workflows/Build/badge.svg\n[coveralls-image]: https://coveralls.io/repos/github/LouisBrunner/sinon-spy-utils/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/LouisBrunner/sinon-spy-utils?branch=master\n[deps-image]: https://david-dm.org/louisbrunner/sinon-spy-utils/status.svg\n[deps-url]: https://david-dm.org/louisbrunner/sinon-spy-utils\n[deps-dev-image]: https://david-dm.org/louisbrunner/sinon-spy-utils/dev-status.svg\n[deps-dev-url]: https://david-dm.org/louisbrunner/sinon-spy-utils?type=dev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisbrunner%2Fsinon-spy-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouisbrunner%2Fsinon-spy-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisbrunner%2Fsinon-spy-utils/lists"}