{"id":17292913,"url":"https://github.com/toddbluhm/sinon-bluebird","last_synced_at":"2025-08-03T13:07:53.106Z","repository":{"id":27995230,"uuid":"31489379","full_name":"toddbluhm/sinon-bluebird","owner":"toddbluhm","description":"[Obsolete] Simple sinon wrapper providing bluebird promise support","archived":false,"fork":false,"pushed_at":"2020-02-13T00:46:58.000Z","size":636,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T20:43:53.252Z","etag":null,"topics":["bluebird","extension","promises","sinon","spies","stub","testing"],"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/toddbluhm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["toddbluhm"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-03-01T06:57:32.000Z","updated_at":"2024-05-17T16:43:05.000Z","dependencies_parsed_at":"2022-08-02T10:53:33.779Z","dependency_job_id":null,"html_url":"https://github.com/toddbluhm/sinon-bluebird","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddbluhm%2Fsinon-bluebird","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddbluhm%2Fsinon-bluebird/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddbluhm%2Fsinon-bluebird/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddbluhm%2Fsinon-bluebird/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toddbluhm","download_url":"https://codeload.github.com/toddbluhm/sinon-bluebird/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248871845,"owners_count":21175302,"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":["bluebird","extension","promises","sinon","spies","stub","testing"],"created_at":"2024-10-15T10:44:47.536Z","updated_at":"2025-04-14T11:31:46.300Z","avatar_url":"https://github.com/toddbluhm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/toddbluhm"],"categories":[],"sub_categories":[],"readme":"\n[![Travis CI](https://img.shields.io/travis/toddbluhm/sinon-bluebird.svg)](https://travis-ci.org/toddbluhm/sinon-bluebird)\n[![Coveralls](https://img.shields.io/coveralls/toddbluhm/sinon-bluebird.svg?maxAge=2592000)](https://coveralls.io/github/toddbluhm/sinon-bluebird)\n[![NPM version](https://img.shields.io/npm/v/sinon-bluebird.svg)](https://www.npmjs.com/package/sinon-bluebird)\n[![Downloads](http://img.shields.io/npm/dm/sinon-bluebird.svg?style=flat)](https://www.npmjs.com/package/sinon-bluebird)\n[![NPM license](https://img.shields.io/npm/l/sinon-bluebird.svg?maxAge=2592000)](https://www.npmjs.com/package/sinon-bluebird)\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n\n# sinon-bluebird\n\n**Obsolete: This package is obsolete as `sinon` now natively supports the `.resolves` and `.rejects` methods\nalong with setting a global `promise` constructor via the `.usingPromise()` method.**\n\nA plugin that adds [bluebird](https://github.com/petkaantonov/bluebird) promise helper methods to [Sinon](https://github.com/cjohansen/Sinon.JS).\n\n## Installation\n\nRun `npm install sinon-bluebird`\n\nor `git clone` then `npm install`\n\nOptionally run unit tests: `npm test`\n\n### Dependencies\n\n**This package requires that both `sinon` and `bluebird` already be installed.**\n\nThis package has peerDependencies of the following:\n\n- `sinon 1.x`\n- `bluebird 3.x`\n\n*If you need a lower version, create an issue and it can be adjusted as necessary. Please, if you do need a lower version, test it first and then make the request.*\n\n## Usage\n\n```js\n// Require in the libs\nvar sinon = require('sinon')\nvar BPromise = require('bluebird')\nrequire('sinon-bluebird')\n\n////// -- Stubs Usage -- //////\n// Create an example function\nvar obj = {\n  foo: function foo() {\n    return 'bar'\n  }\n}\n\n// Stub a function that returns a resolved bluebird BPromise\nsinon.stub(obj, 'foo').resolves('hello world!')\n\n// Execute the stub function\nobj.foo().then(function(val) {\n  // val === 'hello world!'\n})\n\n// Restore the original method\nobj.foo.restore()\n\n// Stub a method that returns a rejected bluebird BPromise\n// Note: For shorthand, just pass in a string and it will be\n// internally wrapped in an Error object (removed in \u003e= v2.0.0)\nsinon.stub(obj, 'foo').rejects('AHHHHHH!!!!')\n\n// Execute the stub function\nobj.foo().catch(function(e) {\n  // e === new Error('AHHHHHH!!!!') [\u003c2.0.0]\n  // e === 'AHHHHHH!!!!' [\u003e=2.0.0]\n});\n\n// Restore back to the original function\nobj.foo.restore()\n\n// Original method back to normal\nobj.foo() // === 'bar'\n////// -- End Stubs Usage -- //////\n\n////// -- Spies Usage -- //////\n\nvar obj = {\n  returnMethod: function (val) {\n    return BPromise.resolve(val)\n  },\n  paramMethod: function (val, prom, val2) {\n    return true\n  }\n}\n\n// Return methods\nvar spy = sinon.spy(obj, 'returnMethod')\n\nobj.returnMethod('Hello') //execute the test function\nspy.returnedPromise('Hello') // === true\n\nobj.returnMethod('World') //execute the test function a second time\nspy.alwaysReturnedPromise('Hello') // === false\n\nspy.restore()\n\n//Called With methods\nspy = sinon.spy(obj, 'paramMethod')\n\nobj.paramMethod(BPromise.resolve('Hello')) //pass in a promise\nspy.calledWithPromise('Hello') // === true\nobj.paramMethod.reset() //reset spy\n\n/* Pass in a promise mixed with regular values\n * Note the rejected promise passed in, any rejected promise will possibly show up in console.log\n * due to how bluebird reports possibly unhandled exceptions (even though in this case we are\n * intentionally passing in a rejected promise)\n*/\nobj.paramMethod('Hello', BPromise.reject('World'), '!')\nspy.calledWithMatch('Hello', 'World', String)  // === true (match allows for comparison by type too!)\n\nobj.paramMethod.restore() //restore the original method back\n\n////// -- End Spies Usage -- //////\n```\n\n## API\n\n### Stubs\n\n**.resolves(value)**\n\nReturns a resolved bluebird promise with the given value\n\n**.rejects(value)**\n\nReturns a rejected bluebird promise with the given value.\n\n*Note: If the given value is a String, that string will be wrapped in an Error object and will be on the message property. **(Removed in \u003e=2.0.0)***\n\n### Spies\n\nAll spy methods are identical to [sinons](http://sinonjs.org/docs/#spies-api) version except it automatically unwraps the bluebird promise (if a promise is returned) and compares directly to the unwrapped value. We append the word `Promise` to each method to denote it unwraps a promise.\n\n#### Return Value Methods\n\n*Promises cannot be in a pending state otherwise an error will be thrown.*\n\n**.returnedPromise(value)**\n\n**.alwaysReturnedPromise(value)**\n\n\n#### Called With Methods\n\n*The promise (or promises) can be anywhere in the list of arguments passed into the spied on function or none at all.*\n\n*Promises cannot be in a pending state otherwise an error will be thrown.*\n\n**.calledWithPromise(value, ...)**\n\n**.calledWithMatchPromise(value, ...)**\n\n**.alwaysCalledWithPromise(value, ...)**\n\n**.alwaysCalledWithMatchPromise(value, ...)**\n\n**.calledWithExactlyPromise(value, ...)**\n\n**.alwaysCalledWithExactlyPromise(value, ...)**\n\n## Inspiration\n\nThanks to  [sinon-as-promised](https://github.com/bendrucker/sinon-as-promised) for inspiration.\n\nIf you're wondering what the main differences are:\n\n- `sinon-as-promised` allows other promise libraries to be used instead of bluebird (`sinon-bluebird` is designed and optimized for use only with bluebird)\n- `sinon-as-promised` only supports `.then`, `.catch`, and `.finally` methods off of the stub (no special bluebird methods like: `.map`, `.bind`, `.spread`, etc...)\n\n## Contributors\n\n- [Brian Moeskau](https://github.com/bmoeskau)\n- [Kevin Moritz](https://github.com/mayorbyrne)\n\n## License\n\n**MIT**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddbluhm%2Fsinon-bluebird","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoddbluhm%2Fsinon-bluebird","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddbluhm%2Fsinon-bluebird/lists"}