Extend Sinon stubs with promise stubbing methods.
Sinon 2 added resolves
and rejects
methods and no longer requires this library.
Installing
npm install sinon-as-promised
If you're using sinon-as-promised in the browser and are not using Browserify/Webpack, use 3.x or earlier.
Usage
var sinon = sinon
You'll only need to require sinon-as-promised once. It attaches the appropriate stubbing functions which will then be available anywhere else you require sinon. It defaults to using native ES6 Promise (or provides a polyfill), but you can use another promise library if you'd like, as long as it exposes a constructor:
// Using Bluebirdvar Bluebird = Bluebird
API
stub.resolves(value)
-> stub
value
Required
Type: any
When called, the stub will return a "thenable" object which will return a promise for the provided value
. Any Promises/A+ compliant library will handle this object properly.
var stub = sinon;stub; ; stub;
stub.rejects(err)
-> stub
err
Required
Type: error
/ string
When called, the stub will return a thenable which will return a reject promise with the provided err
. If err
is a string, it will be set as the message on an Error
object.
stub;stub; stub;;
Examples
License
MIT © Ben Drucker