{"id":13681694,"url":"https://github.com/rstuven/sinonquire","last_synced_at":"2025-07-26T19:32:03.613Z","repository":{"id":57361830,"uuid":"45024414","full_name":"rstuven/sinonquire","owner":"rstuven","description":"Automatically stubs CommonJS modules returned by require() using Sinon.JS","archived":false,"fork":false,"pushed_at":"2016-10-11T14:32:47.000Z","size":11,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T09:41:05.583Z","etag":null,"topics":["commonjs","commonjs-modules","mock","mocking","sinon","stub","stubbing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/rstuven.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}},"created_at":"2015-10-27T07:37:15.000Z","updated_at":"2021-10-25T08:21:43.000Z","dependencies_parsed_at":"2022-09-18T06:04:36.167Z","dependency_job_id":null,"html_url":"https://github.com/rstuven/sinonquire","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Fsinonquire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Fsinonquire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Fsinonquire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Fsinonquire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstuven","download_url":"https://codeload.github.com/rstuven/sinonquire/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227707842,"owners_count":17807567,"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":["commonjs","commonjs-modules","mock","mocking","sinon","stub","stubbing"],"created_at":"2024-08-02T13:01:34.526Z","updated_at":"2024-12-02T10:20:02.369Z","avatar_url":"https://github.com/rstuven.png","language":"JavaScript","readme":"# sinonquire\n\n\u003e Automatically stubs CommonJS modules returned by require/import using Sinon.JS\n\n\u003e Inspired by [Jest's \"mock by default\"](https://facebook.github.io/jest/) concept.\n\n## Installation\n\n```sh\nnpm install --save-dev sinonquire\n```\n\n## Usage\n\nThe following example uses\n[mocha](https://mochajs.org/),\n[chai](http://chaijs.com/) and\n[sinon-chai](https://github.com/domenic/sinon-chai).\n\nFirst, let's tell **sinonquire** which paths should never be loaded as stubs.\n\n`test/index.js`:\n```js\nimport sinonquire from 'sinonquire';\n\nsinonquire.excludePaths(\n  '/node_modules/mocha/',\n  '/my-app/test/'\n);\n```\n\nThen, make sure this configuration module is started before all the tests.\nOne way to do it is using the `--require` argument of mocha CLI.\n\n`package.json`:\n```json\n\"scripts\": {\n  \"test\": \"mocha --recursive --require ./test/index.js\"\n}\n```\n\nOK. Now suppose your app has two main modules, one is a class\nand the other is a function that instantiate the class a couple of times.\n\n\u003e Based on [this Jest example](https://facebook.github.io/jest/docs/automatic-mocking.html).\n\n`lib/User.js`:\n```js\nexport default class User() {\n\n  setName(name) {\n    this.name = name;\n  }\n\n  getName() {\n    return this.name;\n  }\n\n}\n```\n\n`lib/createCouple.js`:\n```js\nimport User from './User.js';\n\nexport default function createCouple(nameA, nameB) {\n  const userA = new User();\n  userA.setName(nameA);\n\n  const userB = new User();\n  userB.setName(nameB);\n\n  return [userA, userB];\n}\n```\n\n`test/createCouple.js`:\n```js\nimport {expect} from 'chai';\nimport sinonquire from 'sinonquire';\n\ndescribe('createCouple', () =\u003e {\n\n  let createCouple;\n\n  beforeEach(() =\u003e {\n    sinonquire.dontStub('../lib/createCouple.js');\n    createCouple = require('../lib/createCouple.js');\n  });\n\n  afterEach(() =\u003e {\n    sinonquire.resetStubs(); // needed for correct spying (eg. calls count)\n  });\n\n  it('should spy instance methods', () =\u003e {\n    const couple = createCouple('userA', 'userB');\n    expect(couple[0].setName).to.have.been.calledWith('userA');\n    expect(couple[1].setName).to.have.been.calledWith('userB');\n  });\n\n  it('should stub instance methods', () =\u003e {\n    const couple = createCouple('userA', 'userB');\n    couple[0].getName.returns('something new');\n    expect(couple[0].getName()).to.equal('something new');\n  });\n\n  it('should spy class instantiation', () =\u003e {\n    createCouple('userA', 'userB');\n    const User = require('../lib/User.js');\n    expect(User).to.have.been.calledTwice;\n    expect(User).to.have.been.calledWithNew;\n  });\n\n});\n\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstuven%2Fsinonquire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstuven%2Fsinonquire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstuven%2Fsinonquire/lists"}