-
-
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
stub#usingPromise and stub#onNthCall have unexpected interactions #1474
Comments
I can't quite wrap my head around this just yet, so I can tell if this is a bug or not. In the meantime, there's an easier way to use third party promise libraries with Sinon const Bluebird = require('bluebird');
const sandbox = require('sinon').sandbox.create().usingPromise(Bluebird);
// all stubs created with this sandbox will use Bluebird for promises Perhaps you can try using that to see if that exposes a flaw in your implementation or makes a bug in Sinon easier to identify? |
Hi there. I'm hitting a similar issue, with a simpler test case: const bluebird = require('bluebird');
const sinon = require('sinon');
const myStub = sinon.stub().usingPromise(bluebird.Promise);
// works
myStub.resolves(['default array']);
myStub().tap(console.log);
// does not work: TypeError: myStub(...).tap is not a function
myStub.onSecondCall().resolves(['second array']);
myStub().tap(console.log); I tested it using both sinon 2.3.5 and 2.3.6, same behavior. I'm using bluebird 3.5.0, with nodejs v6.11.0 on Debian Jessie. Using sinon's sandbox gave me the same unexpected result. |
@fatso83: I noticed this issue upgrading from [email protected] + sinon-as-promised to [email protected], so I never saw such a test work in 2.x. I think a simple example case of the correct ordering is fine, i.e. can you re-write this:
To pass without modifying the |
I guess that the internal stub's attribute I tried to run the @fulax's code in debug mode, and set a break point in the body of the You will see that this.promiseLibrary is correctly set for the original stub (this.promiseLibrary === bluebird constructor). But it is undefined for the behavior defined with onSecondCall(). Edit: Adding this couple of lines in proto.create before returning the brand new behavior seems to solve the issue. if(stub.defaultBehavior && stub.defaultBehavior.promiseLibrary){
behavior.promiseLibrary = stub.defaultBehavior.promiseLibrary;
} |
@HugoMuller good find! any chance of wrapping it into a PR? |
Yeah, I'm working on it ;) |
Fixed by #1484 |
The exact same problem still exists when using |
@HugoMuller since you already understand this part well, would you mind investigating that? |
Ok, I'll take a look at this :) |
done => #1497 |
I ❤️ the speed at which things are being fixed and releases are getting out these days. Even though it was a long birth, we must have been doing something right with the work leading up to 2.0 😄 |
Using the latest version of just about everything:
I run into a couple interactions between
stub#usingPromise
andstub#onNthCall
.My test is testing an internal method call that returns a
Bluebird
promise. I want to make sure that subsequent calls after a failure work correctly.Code:
None of these tests pass, failing on
TypeError: s(...).tap is not a function
. However, I can get them to pass by changing my implementation:But I'd prefer not to change the implementation to fit the tests.
The text was updated successfully, but these errors were encountered: