{"id":18207644,"url":"https://github.com/nubescope/sinon-mongoose","last_synced_at":"2026-06-18T20:00:46.243Z","repository":{"id":2246825,"uuid":"46058046","full_name":"Nubescope/sinon-mongoose","owner":"Nubescope","description":"Extend Sinon stubs for Mongoose methods to test chained methods easily","archived":false,"fork":false,"pushed_at":"2022-12-07T17:52:31.000Z","size":2089,"stargazers_count":88,"open_issues_count":32,"forks_count":27,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-03-15T06:09:28.413Z","etag":null,"topics":["chain-methods","mock","mongoose","sinon","stub"],"latest_commit_sha":null,"homepage":"","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/Nubescope.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":"2015-11-12T14:26:48.000Z","updated_at":"2025-08-27T12:08:12.000Z","dependencies_parsed_at":"2023-01-13T12:15:17.412Z","dependency_job_id":null,"html_url":"https://github.com/Nubescope/sinon-mongoose","commit_stats":null,"previous_names":["underscopeio/sinon-mongoose","gaguirre/sinon-mongoose"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/Nubescope/sinon-mongoose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nubescope%2Fsinon-mongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nubescope%2Fsinon-mongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nubescope%2Fsinon-mongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nubescope%2Fsinon-mongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nubescope","download_url":"https://codeload.github.com/Nubescope/sinon-mongoose/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nubescope%2Fsinon-mongoose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34505422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["chain-methods","mock","mongoose","sinon","stub"],"created_at":"2024-11-03T13:03:48.452Z","updated_at":"2026-06-18T20:00:46.192Z","avatar_url":"https://github.com/Nubescope.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- prettier-ignore-start --\u003e\n# sinon-mongoose [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![devDependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]\n\n\u003e Extend [Sinon][sinon-url] stubs for [Mongoose][mongoose-url] methods to test chained methods easily\n\n## Installation\n\n```sh\n$ npm install sinon-mongoose\n```\n\n\u003e IMPORTANT! As of version **2.2.0** we are supporting sinon \u003e= 5. \n\u003e If you are using sinon \u003c 5 you could have some problems due to some [breaking changes][sinon-5-breaking-changes] in sinon 5. \n\n## Usage\n\n```js\nrequire('sinon')\nrequire('sinon-mongoose')\n```\n\n### With Promises\n\n\u003e If you are using a version \u003c 2 of `sinon-mongoose` we recommend you to use [sinon-as-promised][sinon-as-promised-url] to have `resolves` and `rejects` methods on stubs.\n\nIf you want to test this\n\n```js\nMongooseModel.find()\n  .limit(10)\n  .sort('-date')\n  .exec()\n  .then(function(result) {\n    console.log(result)\n  })\n```\n\nJust `mock` and `expects` as usual and use `chain` to expects the chained methods.\nFinally call `resolves` or `rejects` (remember to require [sinon-as-promised][sinon-as-promised-url]).\n\n```js\nsinon\n  .mock(MongooseModel)\n  .expects('find')\n  .chain('limit')\n  .withArgs(10)\n  .chain('sort')\n  .withArgs('-date')\n  .chain('exec')\n  .resolves('SOME_VALUE')\n```\n\nSee complete [example][promises-example-url]\n\n### With callbacks (no Promises)\n\nIf you want to test this\n\n```js\nMongooseModel.find()\n  .limit(10)\n  .sort('-date')\n  .exec(function(err, result) {\n    console.log(result)\n  })\n```\n\nJust `mock` and `expects` as usually and use `chain` to expects the chained methods.\nFinally `yields` as always.\n\n```js\nsinon\n  .mock(MongooseModel)\n  .expects('find')\n  .chain('limit')\n  .withArgs(10)\n  .chain('sort')\n  .withArgs('-date')\n  .chain('exec')\n  .yields(null, 'SOME_VALUE')\n```\n\nSee complete [example][callbacks-example-url]\n\n## Contributors\n\n[@jniemin](https://github.com/jniemin)  \n[@joebowbeer](https://github.com/joebowbeer)  \n[@YasharF](https://github.com/YasharF)\n\n## License\n\nMIT © [Gonzalo Aguirre]()\n\n[npm-image]: https://badge.fury.io/js/sinon-mongoose.svg\n[npm-url]: https://npmjs.org/package/sinon-mongoose\n[travis-image]: https://travis-ci.org/underscopeio/sinon-mongoose.svg?branch=master\n[travis-url]: https://travis-ci.org/underscopeio/sinon-mongoose\n[daviddm-image]: https://david-dm.org/underscopeio/sinon-mongoose/dev-status.svg?theme=shields.io\n[daviddm-url]: https://david-dm.org/underscopeio/sinon-mongoose?type=dev\n[coveralls-image]: https://coveralls.io/repos/underscopeio/sinon-mongoose/badge.svg\n[coveralls-url]: https://coveralls.io/r/underscopeio/sinon-mongoose\n[sinon-url]: https://github.com/cjohansen/sinon.js\n[mongoose-url]: https://github.com/Automattic/mongoose\n[sinon-as-promised-url]: https://github.com/bendrucker/sinon-as-promised\n[promises-example-url]: https://github.com/underscopeio/sinon-mongoose/tree/master/examples/promises\n[callbacks-example-url]: https://github.com/underscopeio/sinon-mongoose/tree/master/examples/callbacks\n[sinon-5-breaking-changes]: http://sinonjs.org/guides/migrating-to-5.0\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnubescope%2Fsinon-mongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnubescope%2Fsinon-mongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnubescope%2Fsinon-mongoose/lists"}