-
-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
test/stub-test.js
Outdated
var stub = createStub.create(); | ||
|
||
assert(stub.usingPromise); | ||
assert.isTrue(typeof stub.usingPromise === "function"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.isFunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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:
.usingPromise
to higher level objects such as sandboxPurpose
The
usingPromise
method 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
,.done
etc.Solution
Add a
.usingPromise
method that sets the promise library to use.Example using
sinon.stub()
:Example using
sinon.sandbox()
:How to verify
npm install
npm test