Skip to content
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

Sinon method chaining weird behaviour #739

Closed
phnah opened this issue Apr 24, 2015 · 2 comments
Closed

Sinon method chaining weird behaviour #739

phnah opened this issue Apr 24, 2015 · 2 comments

Comments

@phnah
Copy link

@phnah phnah commented Apr 24, 2015

Sinon.js (v1.14.1) has a weird behaviour in method chaining, not sure it's meant to be or a bug:

This (JSBin):

var myStub = sinon.stub().withArgs(1).returns("one").withArgs(2).returns("two");

Will always return "two" no matter what argument you call myStub with.

On the other hand, this (JSBin):

var myStub = sinon.stub();
myStub.withArgs(1).returns("one").withArgs(2).returns("two");

works fine. I'm not sure that SinonJS supports chaining or not.

Thanks, guys.

@mantoni

This comment has been minimized.

Copy link
Member

@mantoni mantoni commented Apr 24, 2015

The "implementation detail" behind this is, that withArgs and returns returns a "behavior" and not the stub instance. The behaviors can be chained. In your first snippet, you assign a behavior instance to myStub.

I can see that this is not really intuitive, but it's not a bug. Maybe it could be clarified in the docs.

@mantoni mantoni closed this Apr 24, 2015
@phnah

This comment has been minimized.

Copy link
Author

@phnah phnah commented Apr 24, 2015

Thanks a lot @mantoni.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.