Added usingPromise method to stub.#1364
Conversation
|
Nice work. I'm not so sure about the name |
|
I would prefer |
|
I'd go for |
usingPromise method to stub.
|
If I have agreement then I will continue with the rest of the implementation this week when I have some "free time" - meaning I steal some time from somewhere else. ;) |
|
@blacksun1 Sure, |
fde9c1c to
8e0e191
Compare
|
Any idea where I should put the documentation for the feature? |
|
Please put documentation into the |
The `usingPromise` method allows the setting of the promise library
that will be used by the resolve and reject method. If it is not set
then it will use the default promise implementation by default.
Example:
```js
var assert = require("assert");
var bluebird = require("bluebird");
var sinon = require("sinon");
var myObject = {};
var myStub = sinon.stub()
.usingPromise(bluebird.Promise)
.resolves(myObject);
myStub()
// Tap should now be available!!!
.tap(function(actual) {
assert.strictEqual(actual, myObject);
})
.catch(function(err) {
console.err("Error", err);
})
```
Documentation still to come.
The `usingPromise` method allows the setting of the promise library
that will be used by the resolve and reject method. If it is not set
then it will use the default promise implementation by default.
Example:
```js
var assert = require("assert");
var bluebird = require("bluebird");
var sinon = require("sinon");
var myObject = {
myMethod: function() { return; }
};
var sandbox = sinon.sandbox.create()
sandbox.stub(myObject);
myObject.myMethod
.usingPromise(bluebird.Promise)
.resolves("baz");
myObject.myMethod()
// Tap should now be available!!!
.tap(function(actual) {
assert.strictEqual(actual, "baz");
});
```
Documentation still to come.
249f818 to
25bfde0
Compare
| var stub = createStub.create(); | ||
|
|
||
| assert(stub.usingPromise); | ||
| assert.isTrue(typeof stub.usingPromise === "function"); |
|
I just wanted to say thanks for doing this, @blacksun1. This should fill the gap left by obsolescing |
|
Never mind my issue comment - found out I could review and merge this using even an old-skool cell phone :-) Thanks! |
|
|
In progress
Things to still be done:
.usingPromiseto higher level objects such as sandboxPurpose
The
usingPromisemethod allows the setting of the promise librarythat will be used by the resolve and reject method. If it is not set then it will use the default promise implementation by default.
This will eventually fix #1354
Background
To allow the setting of a custom promise library when creating a stub that resolves or rejects. Sometimes you need to get back a custom promise library to have access to it's extended methods and so on, such as
.tap,.doneetc.Solution
Add a
.usingPromisemethod that sets the promise library to use.Example using
sinon.stub():Example using
sinon.sandbox():How to verify
npm installnpm test